From: Greg KH <gregkh@suse.de>
To: Lukas Czerner <lczerner@redhat.com>
Cc: Andreas Dilger <adilger.kernel@dilger.ca>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
tytso@mit.edu, sandeen@redhat.com, hch@infradead.org,
axboe@kernel.dk
Subject: Re: [RFC PATCH 0/2 v1] Ioctl for reading block queue information
Date: Fri, 10 Dec 2010 09:34:06 -0800 [thread overview]
Message-ID: <20101210173406.GA11936@suse.de> (raw)
In-Reply-To: <alpine.LFD.2.00.1012101427270.2813@dhcp-lab-213.englab.brq.redhat.com>
On Fri, Dec 10, 2010 at 03:07:20PM +0100, Lukas Czerner wrote:
> On Thu, 9 Dec 2010, Andreas Dilger wrote:
>
> > On 2010-12-09, at 12:20, Greg KH wrote:
> > > On Thu, Dec 09, 2010 at 04:25:35PM +0100, Lukas Czerner wrote:
> > >> For a long time it has been pretty painful to retrieve informations from
> > >> /sys/block/*/queue for particular block device. Not only it is painful
> > >> to retrieve informations within C tool, parsing strings, etc, but one
> > >> have to run into problem even finding the proper path in sysfs.
> > >
> > > What's wrong with using libudev? That should give you all of this
> > > information easily using a .c program without any need to change the
> > > kernel at all.
>
> What's wrong with using libudev ? Well, fist of all I have never heard
> about it:), one can argue this is kind of my fault, and second of all
> the documentation is kind of non-existent (almost).
>
> But, despite this I did gave libudev a quick try and I must say, it
> works, however it is not as simple as calling "ioctl(fd,
> BLKGETQUEUEINFO, &val)" as Andreas pointed out.
>
> So, in my use-case, I have a path to the device provided by the user
> (strictly speaking it may not be device but for example symbolic link
> /dev/mapper/something) and I need to retrieve queue information like
> discard_granularity, discard_alignment etc... usually stored in place
> like /sys/block/sda/queue/*.
>
> With libudev I need to:
>
> 1. create the udev obejct:
>
> udev = udev_new();
> if (!udev) {
> printf("Can't create udev\n");
> exit(1);
> }
>
> 2. Check the path for the block device
>
> stat(name, &buf);
> if (!S_ISBLK(buf.st_mode)) {
> printf("Not a block device\n");
> exit(1);
> }
>
> 3. Get udev device object
>
> dev = udev_device_new_from_devnum(udev, 'b', buf.st_rdev);
> if (!dev) {
> printf("Can not find the device\n");
> exit(1);
> }
>
> 4. Construct path for sysfs attribute I need:
>
> snprintf(path, PATH_MAX, "%s/queue/%s",
> udev_device_get_syspath(dev),
> "discard_granularity");
Hm, what about just using the libudev functions for attributes instead?
That should save you this step, and the next one.
> 5. Open the sysfs file, get page-sized buffer and parse text :-/ (without
> checks now):
>
> read(fd, buffer, pagesize);
> sscanf(buffer, "%lu", &value);
> printf("max_hw_sector_size: %lu\n",value);
>
> Which is opposed to BLKGETQUEUEINFO steps (define val, invoke ioctl,
> check result) a bit longer. But I can definitely see you point, it is
> feasible and since we have libudev we might want to use this in
> userspace. The fact is I would really want to stand up and defend my
> ioctl approach, but libudev just might provide what I need without
> proceeding the just-another-ioctl-madness on kernel lists :).
Please use libudev. What happens next week when we add a new sysfs
attribute to block devices? Then your ioctl just broke and you have to
create a new one.
No, use sysfs for what it was made for, from userspace, don't add custom
ioctls for this.
thanks,
greg k-h
next prev parent reply other threads:[~2010-12-10 17:34 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-09 15:25 [RFC PATCH 0/2 v1] Ioctl for reading block queue information Lukas Czerner
2010-12-09 15:25 ` [PATCH 1/2] blk-sysfs: Clean-up attribute definitions Lukas Czerner
2010-12-09 15:25 ` [PATCH 2/2] Add BLKGETQUEUEINFO for reading block queue attributes Lukas Czerner
2010-12-10 18:39 ` Arnd Bergmann
2010-12-09 19:20 ` [RFC PATCH 0/2 v1] Ioctl for reading block queue information Greg KH
2010-12-09 19:49 ` Andreas Dilger
2010-12-09 19:54 ` Greg KH
2010-12-10 14:07 ` Lukas Czerner
2010-12-10 17:34 ` Greg KH [this message]
2010-12-10 17:59 ` Lukas Czerner
2010-12-10 18:25 ` Kay Sievers
2010-12-10 18:38 ` Lukas Czerner
2010-12-10 17:51 ` Kay Sievers
2010-12-10 17:54 ` Lukas Czerner
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=20101210173406.GA11936@suse.de \
--to=gregkh@suse.de \
--cc=adilger.kernel@dilger.ca \
--cc=axboe@kernel.dk \
--cc=hch@infradead.org \
--cc=lczerner@redhat.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sandeen@redhat.com \
--cc=tytso@mit.edu \
/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;
as well as URLs for NNTP newsgroup(s).