Re: [PATCH] Advanced TCA SCSI/FC disk hotswap driver for kernel 2.5.44

From: Patrick Mochel (mochel@osdl.org)
Date: Thu Oct 24 2002 - 11:51:00 EST


> >Any reason you can't use driverfs for the 2.5 code?
> >
> >
> >
> I'm not sure how driverfs would be used by this particular patch. Could
> you be more specific in stating how this could be used?

I haven't looked extensively at the code, but I'll give you these hints:
Each scsi device gets a directory in the driverfes hierarchy. If you can
obtain a pointer to that device during initialization, you can create
attribute files to handle read/write in that directory.

You need to declare a struct device attribute, which looks like:

(from include/linux/device.h)

struct device_attribute {
        struct attribute attr;
        ssize_t (*show)(struct device * dev, char * buf, size_t count, loff_t off);
        ssize_t (*store)(struct device * dev, const char * buf, size_t count, loff_t off);
};

for each file you want to export.

There is a macro to help, which will fill in the embedded attr structure
for you:

DEVICE_ATTR(name,mode,show,store);

which is equivalent to declaring.

struct device_attribute dev_attr_<name> = { ... };

(You can do it manually, too, if you feel really manly).

I assume that the ability to hotswap drives in a feature supported by a
subset of SCSI drives. I don't know how you handle checking each device,
and it's not really relevant. Whenever you find a device that supports
hotswap, then do something like:

{
        Scsi_Device * scsi_dev;
        ...
        device_create_file(&scsi_dev->sdev_driverfs_dev,&hotswap_attr);
        ...
}

The attribute descriptor will be reused for each device that exports it.
On read() and write(), your show() and store() callbacks will be called,
with a pointer to the device for which it was called as the first
argument.

I hope this all makes sense... If you have any questions, please feel free
to ask.

        -pat

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Thu Oct 31 2002 - 22:00:23 EST