[stgt] RFC [patch] Search /sys/class/bsg/<ctl>/dev for bsg major number.

Nicholas A. Bellinger nab at linux-iscsi.org
Sat Aug 21 23:40:56 CEST 2010


On Sat, 2010-08-21 at 13:42 -0700, Nicholas A. Bellinger wrote:
> On Sat, 2010-08-21 at 16:07 +1000, Mark Harvey wrote:
> > >From a90611630879205ef497821552474e894d463c94 Mon Sep 17 00:00:00 2001
> > From: Mark Harvey <markh794 at gmail.com>
> > Date: Sat, 21 Aug 2010 15:22:48 +1000
> > Subject: Check bsg major number from /sys/class/bsg/<c:t:l>/dev
> > 
> > Signed-off-by: Mark Harvey <markh794 at gmail.com>
> > ---
> >  usr/bs_sg.c |   35 ++++++++++++++++++++++++++++++++---
> >  1 files changed, 32 insertions(+), 3 deletions(-)
> > 
> > diff --git a/usr/bs_sg.c b/usr/bs_sg.c
> > index dfd49c3..7fc9787 100644
> > --- a/usr/bs_sg.c
> > +++ b/usr/bs_sg.c
> > @@ -269,6 +269,34 @@ static void bs_sg_cmd_complete(int fd, int
> > events, void *data)
> >  	cmd->scsi_cmd_done(cmd, io_hdr.status);
> >  }
> > 
> > +static int get_bsg_major(char *path)
> > +{
> > +	FILE *devfd;
> > +	char majorno[8];
> > +	char dev[128];
> > +	int ch;
> > +	int i;
> > +
> > +	dev[0] = '\0';
> > +	strncat(dev, "/sys/class/bsg/", 16);
> > +	strncat(dev, &path[9], 64);
> > +	strncat(dev, "/dev", 5);
> > +	devfd = fopen(dev, "r");
> > +	if (!devfd)
> > +		return -1;
> > +	ch = fgetc(devfd);
> > +	for (i = 0; i < 7; i++) {
> > +		if (ch == ':') {
> > +			majorno[i] = '\0';
> > +			break;
> > +		}
> > +		majorno[i] = ch;
> > +		ch = fgetc(devfd);
> > +	}
> > +	fclose(devfd);
> > +	return atoi(majorno);
> > +}
> > +
> >  static int (char *path)
> >  {
> >  	struct stat st;
> > @@ -287,9 +315,10 @@ static int chk_sg_device(char *path)
> >  	if (major(st.st_rdev) == SCSI_GENERIC_MAJOR)
> >  		return 0;
> > 
> > -	/* This is not yet defined in include/linux/major.h.. */
> > -	if (major(st.st_rdev) == 254)
> > -		return 1;
> > +	if (!strncmp("/dev/bsg", path, 8)) {
> > +		if (major(st.st_rdev) == get_bsg_major(path))
> > +			return 0;

Actually sorry, one thing here..  When we have detected a BSG device,
chk_sg_device() needs to return 1 to signal it's usage to bs_sg_open().

Best,

--nab


--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html



More information about the stgt mailing list