[PATCH] ioctl: implement NBD_* ioctl decoding

Eugene Syromiatnikov esyr at redhat.com
Sun Sep 23 04:59:15 UTC 2018


On Sat, Sep 22, 2018 at 11:52:29AM +0200, Elvira Khabirova wrote:
> On Fri, 21 Sep 2018 22:39:29 +0200, Eugene Syromiatnikov <esyr at redhat.com> wrote:
> > On Fri, Sep 21, 2018 at 04:42:50PM +0200, Elvira Khabirova wrote:
> > > +	ioctl(-1, NBD_SET_FLAGS, 0);
> > > +	printf("ioctl(-1, NBD_SET_FLAGS, 0) = -1 EBADF (%m)\n");
> > > +	ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_HAS_FLAGS);
> > > +	printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_HAS_FLAGS) = -1 EBADF (%m)\n");
> > > +	ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_READ_ONLY);
> > > +	printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_READ_ONLY) = -1 EBADF (%m)\n");
> > > +	ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_FLUSH);
> > > +	printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_FLUSH) = -1 EBADF (%m)\n");
> > > +	ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_FUA);
> > > +	printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_FUA) = -1 EBADF (%m)\n");
> > > +	ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_TRIM);
> > > +	printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_SEND_TRIM) = -1 EBADF (%m)\n");
> > > +	ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_CAN_MULTI_CONN);
> > > +	printf("ioctl(-1, NBD_SET_FLAGS, NBD_FLAG_CAN_MULTI_CONN) = -1 EBADF (%m)\n");  
> > 
> > It is probably worth checking various flag combinations, including bits
> > for which there are no constants defined, in order to avoid situation like
> > v4.21~159.
> 
> Could you elaborate?

When only a single flag is checked, it is no different than printing a
named constant.  Usually, printing something like ~0ULL is enough.

> 
> > ioctl(_IO(0xab, 0)) and ioctl(_IO(0xab, 11)) decoding is also probably worth
> > checking.
> 
> ioctl(_IO(0xab, 0)) is NBD_SET_SOCK.

My bad, some ioctl groups start numbering from 1.

> 
> > NBD_MAGIC is probably worth adding to xlat/fsmagic.in. I'm not sure,
> > however, as it's a private definition. (Funnily enough,
> > Documentation/process/magic-number.rst mentions that it is declared
> > under the name LO_MAGIC in the file "include/linux/nbd.h" which is not
> > true at all.)
> 
> NBD_MAGIC is not an fsmagic; nbd does not care about filesystems.

Right; it's not even used now, it seems, and it was used before for
protecting struct nbd_device.


More information about the Strace-devel mailing list