From: Ira Weiny <ira.weiny@intel.com>
To: Dave Jiang <dave.jiang@intel.com>,
Ira Weiny <ira.weiny@intel.com>,
"Alison Schofield" <alison.schofield@intel.com>
Cc: Vishal Verma <vishal.l.verma@intel.com>,
Jonathan Cameron <jonathan.cameron@huawei.com>,
Fan Ni <fan.ni@samsung.com>,
Navneet Singh <navneet.singh@intel.com>,
Dan Williams <dan.j.williams@intel.com>,
<linux-cxl@vger.kernel.org>, <nvdimm@lists.linux.dev>
Subject: Re: [ndctl PATCH v2 5/6] ndctl/cxl: Add extent output to region query
Date: Tue, 5 Nov 2024 14:53:09 -0600 [thread overview]
Message-ID: <672a85b55559_166959294db@iweiny-mobl.notmuch> (raw)
In-Reply-To: <4dccf252-8827-4d5e-9417-8b52dbed132d@intel.com>
Dave Jiang wrote:
[snip]
> > +static void cxl_extents_init(struct cxl_region *region)
> > +{
> > + const char *devname = cxl_region_get_devname(region);
> > + struct cxl_ctx *ctx = cxl_region_get_ctx(region);
> > + char *extent_path, *dax_region_path;
> > + struct dirent *de;
> > + DIR *dir = NULL;
> > +
> > + if (region->extents_init)
> > + return;
> > + region->extents_init = 1;
> > +
> > + dbg(ctx, "Checking extents: %s\n", region->dev_path);
> > +
> > + dax_region_path = calloc(1, strlen(region->dev_path) + 64);
> > + if (!dax_region_path) {
> > + err(ctx, "%s: allocation failure\n", devname);
> > + return;
> > + }
> > +
> > + extent_path = calloc(1, strlen(region->dev_path) + 100);
> > + if (!extent_path) {
> > + err(ctx, "%s: allocation failure\n", devname);
> > + free(dax_region_path);
> > + return;
> > + }
> > +
> > + sprintf(dax_region_path, "%s/dax_region%d",
> > + region->dev_path, region->id);
> > + dir = opendir(dax_region_path);
> > + if (!dir) {
> > + err(ctx, "no extents found: %s\n", dax_region_path);
>
> Also printing the errno may be helpful
Yea. strerror()
>
> > + free(extent_path);
> > + free(dax_region_path);
> > + return;
> > + }
> > +
> > + while ((de = readdir(dir)) != NULL) {
> > + struct cxl_region_extent *extent;
> > + char buf[SYSFS_ATTR_SIZE];
> > + u64 offset, length;
> > + int id, region_id;
> > +
> > + if (sscanf(de->d_name, "extent%d.%d", ®ion_id, &id) != 2)
> > + continue;
> > +
> > + sprintf(extent_path, "%s/extent%d.%d/offset",
> > + dax_region_path, region_id, id);
> > + if (sysfs_read_attr(ctx, extent_path, buf) < 0) {
> > + err(ctx, "%s: failed to read extent%d.%d/offset\n",
> > + devname, region_id, id);
> > + continue;
> > + }
> > +
> > + offset = strtoull(buf, NULL, 0);
> > + if (offset == ERANGE) {
>
> I think it needs to be coded like:
> if (offset == ULLONG_MAX) {
Yep... I fell in the habit of the error being returned...
>
> Not sure why specifically checking for ERANGE, but should be checking against errno for that if needed.
Because I was thinking about strtoull() having odd error handling and was
stupid and did not look at the man page. If you look closely at the man page
full error coverage needs to be.
errno = 0;
offset = strtoull(...);
if ((offset == ULLONG_MAX) || (offset == 0 && errno == EINVAL)) {
...
}
But sysfs is not going to return an invalid value... So ULLONG_MAX is all we
need to check for.
Thanks!
Ira
>
> DJ
next prev parent reply other threads:[~2024-11-05 20:53 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-05 2:10 [ndctl PATCH v2 0/6] ndctl: DCD additions Ira Weiny
2024-11-05 2:10 ` [ndctl PATCH v2 1/6] ndctl/cxl-events: Don't fail test until event counts are reported Ira Weiny
2024-11-05 15:44 ` Dave Jiang
2025-02-09 1:25 ` Alison Schofield
2024-11-05 2:10 ` [ndctl PATCH v2 2/6] ndctl/cxl/region: Report max size for region creation Ira Weiny
2024-11-05 15:45 ` Dave Jiang
2024-11-05 21:46 ` Fan Ni
2025-02-09 1:26 ` Alison Schofield
2024-11-05 2:10 ` [ndctl PATCH v2 3/6] ndctl: Separate region mode from decoder mode Ira Weiny
2024-11-05 15:56 ` Dave Jiang
2024-11-05 21:49 ` Fan Ni
2024-11-05 2:10 ` [ndctl PATCH v2 4/6] cxl/region: Add creation of Dynamic capacity regions ira.weiny
2024-11-05 16:38 ` Dave Jiang
2024-11-05 20:38 ` Ira Weiny
2024-11-06 3:16 ` Alison Schofield
2024-11-07 18:00 ` Alison Schofield
2024-11-07 21:28 ` Ira Weiny
2024-11-07 18:27 ` Alison Schofield
2024-11-07 18:52 ` Alison Schofield
2024-11-08 20:17 ` Ira Weiny
2024-11-05 2:10 ` [ndctl PATCH v2 5/6] ndctl/cxl: Add extent output to region query Ira Weiny
2024-11-05 17:04 ` Dave Jiang
2024-11-05 20:53 ` Ira Weiny [this message]
2024-11-07 18:13 ` Alison Schofield
2024-11-08 20:16 ` Ira Weiny
2024-11-05 2:10 ` [ndctl PATCH v2 6/6] ndctl/cxl/test: Add Dynamic Capacity tests Ira Weiny
2024-11-05 17:11 ` Dave Jiang
2024-11-05 19:53 ` Ira Weiny
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=672a85b55559_166959294db@iweiny-mobl.notmuch \
--to=ira.weiny@intel.com \
--cc=alison.schofield@intel.com \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=fan.ni@samsung.com \
--cc=jonathan.cameron@huawei.com \
--cc=linux-cxl@vger.kernel.org \
--cc=navneet.singh@intel.com \
--cc=nvdimm@lists.linux.dev \
--cc=vishal.l.verma@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox