Re: [PATCHv2] usb: gadget: storage: optional SCSI WRITE FUA bit

From: Andy Shevchenko
Date: Wed Jul 14 2010 - 09:45:10 EST


2010/7/14 MichaÅ Nazarewicz <m.nazarewicz@xxxxxxxxxxx>:
> On Wed, 14 Jul 2010 11:05:31 +0200, Andy Shevchenko
> <andy.shevchenko@xxxxxxxxx> wrote:
>>
>> MS Windows mounts removable storage in "Removal optimized mode" by
>> default. All the writes to the media are synchronous which is achieved
>> by setting FUA (Force Unit Access) bit in SCSI WRITE(10,12) commands.
>> This prevents I/O requests aggregation in block layer dramatically
>> decreasing performance.
>
>> diff --git a/drivers/usb/gadget/file_storage.c
>> b/drivers/usb/gadget/file_storage.c
>> index b49d86e..45f58d9 100644
>> --- a/drivers/usb/gadget/file_storage.c
>> +++ b/drivers/usb/gadget/file_storage.c
>> @@ -93,6 +93,8 @@
>> Â*   removable        Default false, boolean for removable media
>> Â* Â Â luns=N Â Â Â Â Â Â Â Â ÂDefault N = number of filenames, number of
>> Â* Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â LUNs to support
>> + * Â Â fua=b[,b...] Â Â Â Â Â ÂDefault false, booleans for ignore FUA
>> flag
>> + * Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â in SCSI WRITE(6,10,12) commands
>
> I wonder if it makes sense to make it per-LUN. ÂI would imagine that it's
> great
> to ignore FUA if the device has its own power supply in which case after
> disconnect
> the data won't be lost. ÂThis is a per-device property not really per-LUN.
> ÂAs such
> I'd make this option global for the gadget.
Make sense only for removable media with one partition.
Otherwise. why we have sync option per partition f.e., not per device?

>> @@ -743,6 +752,24 @@ static ssize_t fsg_store_ro(struct device *dev,
>> struct device_attribute *attr,
>> Â Â Â Âreturn rc;
>> Â}
>> +static ssize_t fsg_store_fua(struct device *dev, struct device_attribute
>> *attr,
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Âconst char *buf, size_t count)
>> +{
>> +    ssize_t     rc = count;
>
> Not really needed here.
See below

>
>> + Â Â Â struct fsg_lun Â*curlun = fsg_lun_from_dev(dev);
>> +    int       i;
>> +
>> + Â Â Â if (sscanf(buf, "%d", &i) != 1)
>> + Â Â Â Â Â Â Â return -EINVAL;
>
> Why not simple_strtol() directly?
I did it in the same way like fsg_store_ro() does.
I have no objections to back to previous solution.

>> +
>> + Â Â Â if (curlun->fua)
>> + Â Â Â Â Â Â Â fsg_lun_fsync_sub(curlun);
>
> Shouldn't that read something like:
>
> + Â Â Â if (!curlun->fua && i)
> + Â Â Â Â Â Â Â fsg_lun_fsync_sub(curlun);
>
> ie. there is no sense in syncing if FUA was active (in which case all
> writes were synced already, right?) or if the new value is false (since
> then user does not won't syncing).
The idea is to sync data before switching from async mode.
Actually fua = 1 means ignorance of that flag.


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