All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: gadget: f_mass_storage: forced_eject attribute
@ 2022-07-06 17:46 Maxim Devaev
  2022-07-06 17:54 ` Maxim Devaev
  2022-07-06 18:13 ` Greg KH
  0 siblings, 2 replies; 4+ messages in thread
From: Maxim Devaev @ 2022-07-06 17:46 UTC (permalink / raw)
  To: linux-usb; +Cc: stern, balbi, gregkh, caihuoqing, mdevaev, linux-kernel

It allows to reset prevent_medium_removal flag and "eject" the image.

The patch is a completely alternative implementation of the previously
proposed [1], the idea of which was born after the mentioned discussion.

Signed-off-by: Maxim Devaev <mdevaev@gmail.com>
Link: https://lore.kernel.org/lkml/20220406092445.215288-1-mdevaev@gmail.com [1]
---
 drivers/usb/gadget/function/f_mass_storage.c | 25 ++++++++++++++++++++
 drivers/usb/gadget/function/storage_common.c | 11 +++++++++
 drivers/usb/gadget/function/storage_common.h |  2 ++
 3 files changed, 38 insertions(+)

diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c
index 6ad669dde41c..00cac2a38178 100644
--- a/drivers/usb/gadget/function/f_mass_storage.c
+++ b/drivers/usb/gadget/function/f_mass_storage.c
@@ -2520,10 +2520,21 @@ static ssize_t file_store(struct device *dev, struct device_attribute *attr,
 	return fsg_store_file(curlun, filesem, buf, count);
 }
 
+static ssize_t forced_eject_store(struct device *dev,
+				  struct device_attribute *attr,
+				  const char *buf, size_t count)
+{
+	struct fsg_lun		*curlun = fsg_lun_from_dev(dev);
+	struct rw_semaphore	*filesem = dev_get_drvdata(dev);
+
+	return fsg_store_forced_eject(curlun, filesem, buf, count);
+}
+
 static DEVICE_ATTR_RW(nofua);
 /* mode wil be set in fsg_lun_attr_is_visible() */
 static DEVICE_ATTR(ro, 0, ro_show, ro_store);
 static DEVICE_ATTR(file, 0, file_show, file_store);
+static DEVICE_ATTR_WO(forced_eject);
 
 /****************************** FSG COMMON ******************************/
 
@@ -2677,6 +2688,7 @@ static struct attribute *fsg_lun_dev_attrs[] = {
 	&dev_attr_ro.attr,
 	&dev_attr_file.attr,
 	&dev_attr_nofua.attr,
+	&dev_attr_forced_eject.attr,
 	NULL
 };
 
@@ -3090,6 +3102,18 @@ static ssize_t fsg_lun_opts_inquiry_string_store(struct config_item *item,
 
 CONFIGFS_ATTR(fsg_lun_opts_, inquiry_string);
 
+static ssize_t fsg_lun_opts_forced_eject_store(struct config_item *item,
+					       const char *page, size_t len)
+{
+	struct fsg_lun_opts *opts = to_fsg_lun_opts(item);
+	struct fsg_opts *fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
+
+	return fsg_store_forced_eject(opts->lun, &fsg_opts->common->filesem,
+				      page, len);
+}
+
+CONFIGFS_ATTR_WO(fsg_lun_opts_, forced_eject);
+
 static struct configfs_attribute *fsg_lun_attrs[] = {
 	&fsg_lun_opts_attr_file,
 	&fsg_lun_opts_attr_ro,
@@ -3097,6 +3121,7 @@ static struct configfs_attribute *fsg_lun_attrs[] = {
 	&fsg_lun_opts_attr_cdrom,
 	&fsg_lun_opts_attr_nofua,
 	&fsg_lun_opts_attr_inquiry_string,
+	&fsg_lun_opts_attr_forced_eject,
 	NULL,
 };
 
diff --git a/drivers/usb/gadget/function/storage_common.c b/drivers/usb/gadget/function/storage_common.c
index b859a158a414..8cd95bf7831f 100644
--- a/drivers/usb/gadget/function/storage_common.c
+++ b/drivers/usb/gadget/function/storage_common.c
@@ -519,4 +519,15 @@ ssize_t fsg_store_inquiry_string(struct fsg_lun *curlun, const char *buf,
 }
 EXPORT_SYMBOL_GPL(fsg_store_inquiry_string);
 
+ssize_t fsg_store_forced_eject(struct fsg_lun *curlun, struct rw_semaphore *filesem,
+			       const char *buf, size_t count)
+{
+	int ret;
+
+	curlun->prevent_medium_removal = 0;
+	ret = fsg_store_file(curlun, filesem, "", 0);
+	return ret < 0 ? ret : count;
+}
+EXPORT_SYMBOL_GPL(fsg_store_forced_eject);
+
 MODULE_LICENSE("GPL");
diff --git a/drivers/usb/gadget/function/storage_common.h b/drivers/usb/gadget/function/storage_common.h
index bdeb1e233fc9..0a544a82cbf8 100644
--- a/drivers/usb/gadget/function/storage_common.h
+++ b/drivers/usb/gadget/function/storage_common.h
@@ -219,5 +219,7 @@ ssize_t fsg_store_removable(struct fsg_lun *curlun, const char *buf,
 			    size_t count);
 ssize_t fsg_store_inquiry_string(struct fsg_lun *curlun, const char *buf,
 				 size_t count);
+ssize_t fsg_store_forced_eject(struct fsg_lun *curlun, struct rw_semaphore *filesem,
+			       const char *buf, size_t count);
 
 #endif /* USB_STORAGE_COMMON_H */
-- 
2.37.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: gadget: f_mass_storage: forced_eject attribute
  2022-07-06 17:46 [PATCH] usb: gadget: f_mass_storage: forced_eject attribute Maxim Devaev
@ 2022-07-06 17:54 ` Maxim Devaev
  2022-07-06 18:13 ` Greg KH
  1 sibling, 0 replies; 4+ messages in thread
From: Maxim Devaev @ 2022-07-06 17:54 UTC (permalink / raw)
  To: linux-usb; +Cc: stern, balbi, gregkh, caihuoqing, linux-kernel

В Wed,  6 Jul 2022 20:46:34 +0300
Maxim Devaev <mdevaev@gmail.com> wrote:

> The patch is a completely alternative implementation of the previously
> proposed [1], the idea of which was born after the mentioned discussion.
> Link: https://lore.kernel.org/lkml/20220406092445.215288-1-mdevaev@gmail.com [1]

A small comment after that, which is not worth mentioning in the body of the patch.
As discussed in the previous thread, I made a clean implementation to reset
the prevent_medium_removal flag instead of using SIGUSR1, tested it myself,
and then on several thousand of my users. I haven't received a single complaint
in a few months, so I guess everything is working as intended.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: gadget: f_mass_storage: forced_eject attribute
  2022-07-06 17:46 [PATCH] usb: gadget: f_mass_storage: forced_eject attribute Maxim Devaev
  2022-07-06 17:54 ` Maxim Devaev
@ 2022-07-06 18:13 ` Greg KH
  2022-07-06 20:53   ` Maxim Devaev
  1 sibling, 1 reply; 4+ messages in thread
From: Greg KH @ 2022-07-06 18:13 UTC (permalink / raw)
  To: Maxim Devaev; +Cc: linux-usb, stern, balbi, caihuoqing, linux-kernel

On Wed, Jul 06, 2022 at 08:46:34PM +0300, Maxim Devaev wrote:
> It allows to reset prevent_medium_removal flag and "eject" the image.
> 
> The patch is a completely alternative implementation of the previously
> proposed [1], the idea of which was born after the mentioned discussion.
> 
> Signed-off-by: Maxim Devaev <mdevaev@gmail.com>
> Link: https://lore.kernel.org/lkml/20220406092445.215288-1-mdevaev@gmail.com [1]
> ---
>  drivers/usb/gadget/function/f_mass_storage.c | 25 ++++++++++++++++++++
>  drivers/usb/gadget/function/storage_common.c | 11 +++++++++
>  drivers/usb/gadget/function/storage_common.h |  2 ++
>  3 files changed, 38 insertions(+)
> 
> diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c
> index 6ad669dde41c..00cac2a38178 100644
> --- a/drivers/usb/gadget/function/f_mass_storage.c
> +++ b/drivers/usb/gadget/function/f_mass_storage.c
> @@ -2520,10 +2520,21 @@ static ssize_t file_store(struct device *dev, struct device_attribute *attr,
>  	return fsg_store_file(curlun, filesem, buf, count);
>  }
>  
> +static ssize_t forced_eject_store(struct device *dev,
> +				  struct device_attribute *attr,
> +				  const char *buf, size_t count)
> +{
> +	struct fsg_lun		*curlun = fsg_lun_from_dev(dev);
> +	struct rw_semaphore	*filesem = dev_get_drvdata(dev);
> +
> +	return fsg_store_forced_eject(curlun, filesem, buf, count);
> +}
> +
>  static DEVICE_ATTR_RW(nofua);
>  /* mode wil be set in fsg_lun_attr_is_visible() */
>  static DEVICE_ATTR(ro, 0, ro_show, ro_store);
>  static DEVICE_ATTR(file, 0, file_show, file_store);
> +static DEVICE_ATTR_WO(forced_eject);

You have to document sysfs files in Documentation/ABI/ in order for us
to be able to accept them.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] usb: gadget: f_mass_storage: forced_eject attribute
  2022-07-06 18:13 ` Greg KH
@ 2022-07-06 20:53   ` Maxim Devaev
  0 siblings, 0 replies; 4+ messages in thread
From: Maxim Devaev @ 2022-07-06 20:53 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-usb, stern, balbi, caihuoqing, linux-kernel

В Wed, 6 Jul 2022 20:13:54 +0200
Greg KH <gregkh@linuxfoundation.org> wrote:

> You have to document sysfs files in Documentation/ABI/ in order for us
> to be able to accept them.

I've added this and also the documentation for configfs. Submitted as v2 patch.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-07-06 20:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-06 17:46 [PATCH] usb: gadget: f_mass_storage: forced_eject attribute Maxim Devaev
2022-07-06 17:54 ` Maxim Devaev
2022-07-06 18:13 ` Greg KH
2022-07-06 20:53   ` Maxim Devaev

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.