Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp23375pxb; Tue, 12 Apr 2022 15:43:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnXNHqZ0HUDQHOqWC0U66vg1JEM7k31KURtg4QCxnkrg6y80kQpY+9zetR9/BOQSwrqdxK X-Received: by 2002:a17:903:11d0:b0:155:c240:a2c0 with SMTP id q16-20020a17090311d000b00155c240a2c0mr39599142plh.143.1649803386239; Tue, 12 Apr 2022 15:43:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649803386; cv=none; d=google.com; s=arc-20160816; b=0nU/fTeh/ReB2H+VC6c9m3SN2S/2J/lhLOLh0/pyxObpsWOApX8LKTiV3BFBHDN8PO P7Y/7gjbpvtrt5p87q1clI439B8mLIHXK1rRVeImxRWHkMXfycUbRbtnqf0qhJTNBwNb 1KKO2zGXDRJuzYtGa8G97N7D94HZENWQjDvGYZJ+nWMlRctxCX3Q7JBb9U5xP6oh7NYo dPZRIBu7fdcMSHEvRgDaOesJQ5n13LkSv5ZB6T1MMO9+ij/oI+MudbpVVsm1b+sPhkVs WlgxTWGVqR78pXv+0Wif1+00e5vtP6hBIjQz8gN8iCWbLs0FbSw2ZoM+4TG12e+2NXiS NAjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=uHqATj/VaGInvfLxvc/l7dOSPYdjzKbzcKU4MhNdico=; b=MLkuKKj7ndDfhgC1QGifIYPNrLB6wG8E6k3iiy/azCTr6FTdLYdPF4nTnsZVT//j1J NbuT6Sk/EThGj1chWddCNIfUJGLnT4dhTL5fbfHAzJTLxzQxFtU1PwbwVFKHWlga19k9 Wo3rDSVt5oovavx0dSAYYe9YkdTm9f2em12zoahiSuoWKjSaF71ar8UgO7crM43VomXD dzX2IIuBbKFaIzDc7i1ZoDJCufUFM7AzFWYjmTROXrW2YBORVC6mw9DIUm0S8HTkaQ9I v6LQwYsFTTJ3OoSthwjvNjHYr55ahqRcuxSx+mstRIbua0/Jh7AOuNXue6tmqkvXieaU cqOA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id 14-20020a630c4e000000b003822f3c78cfsi3956214pgm.683.2022.04.12.15.43.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 15:43:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1609218B263; Tue, 12 Apr 2022 14:24:45 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231389AbiDIUYo (ORCPT + 99 others); Sat, 9 Apr 2022 16:24:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231276AbiDIUYk (ORCPT ); Sat, 9 Apr 2022 16:24:40 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 6D24B2BCE for ; Sat, 9 Apr 2022 13:22:30 -0700 (PDT) Received: (qmail 293258 invoked by uid 1000); 9 Apr 2022 16:22:29 -0400 Date: Sat, 9 Apr 2022 16:22:29 -0400 From: Alan Stern To: Maxim Devaev Cc: linux-usb@vger.kernel.org, Felipe Balbi , Greg Kroah-Hartman , Cai Huoqing , linux-kernel@vger.kernel.org Subject: Re: [PATCH] usb: gadget: f_mass_storage: break IO operations via configfs Message-ID: References: <20220406195234.4f63cb4a@reki> <20220406213634.104cae45@reki> <20220407204553.35cead72@reki> <20220409115756.4f9b015d@reki> <20220409170837.02f0853f@reki> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220409170837.02f0853f@reki> X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Apr 09, 2022 at 05:08:37PM +0300, Maxim Devaev wrote: > В Sat, 9 Apr 2022 09:46:32 -0400 > Alan Stern wrote: > > > On Sat, Apr 09, 2022 at 11:57:56AM +0300, Maxim Devaev wrote: > > > В Fri, 8 Apr 2022 10:59:45 -0400 > > > Alan Stern wrote: > > > > > At least there is one situation where the behavior of f_mass_storage differs > > > > > from the behavior of a real drive. What happens when you click on the physical > > > > > "eject" button? > > > > > > > > If the host has prevented ejection, nothing happens. Otherwise the disc > > > > gets ejected. > > > > > > > > > Yes, the OS can block this, but the problem is that we don't have > > > > > an "eject" here. > > > > > > > > What do you mean? Writing an empty string to the sysfs "file" attribute > > > > is the virtual analog of pressing the eject button. > > > > > > But I can't eject the disc event it's not mounted on Linux host. It seems to me > > > it differs from the real drive behavior. > > > > It sounds like either there's a bug or else you're not doing the right > > thing. Tell me exactly what you do when this fails. > > I'm using Raspberry Pi with DWC2. So: > - Connect RPi-based gadget to the Linux host. > - Set image in the "file" attribute. Exactly what is the full pathname you're using for the "file" attribute? > - Mount gadget's drive on the Linux host. > - Umount it. > - Try to eject using emptying the "file" attribute. > - Get EBUSY error. This must mean that some program on the host is keeping the device file open, even though it isn't mounted. (I tried running a similar test on my system and it worked perfectly, with no other programs accessing the device). You might be able to identify which program is accessing the device by running lsof on the host and searching the output for the device name. I also tried sending a USR1 signal to the driver's kernel thread while an image was mounted and being accessed. It did clear the prevent_allow flag, so I could eject the image. But it also caused a 30-second delay on the host, as predicted. Now, maybe you don't care about such delays when you're going to eject the media anyway, but it still seems like a bad thing to do. > > > I have reflected on the rest of your arguments and changed my mind. > > > I think that "forced_eject" for a specific lun without interrupting operations would > > > really be the best solution. I wrote a simple patch and tested it, everything seems > > > to work. What do you think about something like this? > > > > > > > > > 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); > > > int ret; > > > > > > opts->lun->prevent_medium_removal = 0; > > > ret = fsg_store_file(opts->lun, &fsg_opts->common->filesem, "", 0); > > > return ret < 0 ? ret : len; > > > } > > > > > > CONFIGFS_ATTR_WO(fsg_lun_opts_, forced_eject); > > > > The basic idea is right. But this should not be a CONFIGFS option; it > > should be an ordinary LUN attribute. For an example, see the definition of > > file_store() in f_mass_storage.c; your routine should look very similar. > > Okay, but where this attribute is located in sysfs? How can I use it? Well, it's going to be in different places depending on what UDC driver your gadget uses. On my system I'm using the dummy_udc driver, so the sysfs "file" attribute is located at: /sys/devices/platform/dummy_ucd.0/gadget/lun0/file If instead you're looking at /sys/module/g_mass_storage/parameters/file or in some configfs directory, that's the wrong place. You can eject the media simply by doing (as root): echo >/sys/devices/.../gadget/lun0/file (fill in the "..." appropriately for your system). > Sorry for the stupid question. Not at all. Alan Stern