linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cdrom: do not print info list when there is no cdrom device
@ 2022-04-08  8:42 Enze Li
  2022-04-08 12:34 ` Jens Axboe
  0 siblings, 1 reply; 6+ messages in thread
From: Enze Li @ 2022-04-08  8:42 UTC (permalink / raw)
  To: phil; +Cc: linux-kernel, linux-block, axboe

There is no need to print a list of cdrom entries with blank info when
no cdrom device exists.  With this patch applied, we get:

================================================
$ cat /proc/sys/dev/cdrom/info
CD-ROM information, Id:cdrom.c 3.20 2003/12/17

No device found.

================================================

BTW, I also formatted the argument list of the cdrom_sysctl_info
function, using tabs instead of spaces.

Signed-off-by: Enze Li <lienze@kylinos.cn>
---
 drivers/cdrom/cdrom.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index 7bd10d63ddbe..33a51303f565 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -3507,7 +3507,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
 }
 
 static int cdrom_sysctl_info(struct ctl_table *ctl, int write,
-                           void *buffer, size_t *lenp, loff_t *ppos)
+			     void *buffer, size_t *lenp, loff_t *ppos)
 {
 	int pos;
 	char *info = cdrom_sysctl_settings.info;
@@ -3522,6 +3522,11 @@ static int cdrom_sysctl_info(struct ctl_table *ctl, int write,
 
 	pos = sprintf(info, "CD-ROM information, " VERSION "\n");
 	
+	if (list_empty(&cdrom_list)) {
+		scnprintf(info + pos, max_size - pos, "\nNo device found.\n");
+		goto doit;
+	}
+
 	if (cdrom_print_info("\ndrive name:\t", 0, info, &pos, CTL_NAME))
 		goto done;
 	if (cdrom_print_info("\ndrive speed:\t", 0, info, &pos, CTL_SPEED))
-- 
2.25.1


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

* Re: [PATCH] cdrom: do not print info list when there is no cdrom device
  2022-04-08  8:42 [PATCH] cdrom: do not print info list when there is no cdrom device Enze Li
@ 2022-04-08 12:34 ` Jens Axboe
  2022-04-09  4:25   ` Enze Li
  0 siblings, 1 reply; 6+ messages in thread
From: Jens Axboe @ 2022-04-08 12:34 UTC (permalink / raw)
  To: Enze Li, phil; +Cc: linux-kernel, linux-block

On 4/8/22 2:42 AM, Enze Li wrote:
> There is no need to print a list of cdrom entries with blank info when
> no cdrom device exists.  With this patch applied, we get:
> 
> ================================================
> $ cat /proc/sys/dev/cdrom/info
> CD-ROM information, Id:cdrom.c 3.20 2003/12/17
> 
> No device found.
> 
> ================================================

And what did we get before?

Will this potentially break applications that parse it?

-- 
Jens Axboe


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

* Re: [PATCH] cdrom: do not print info list when there is no cdrom device
  2022-04-08 12:34 ` Jens Axboe
@ 2022-04-09  4:25   ` Enze Li
  2022-04-09  8:16     ` Phillip Potter
  0 siblings, 1 reply; 6+ messages in thread
From: Enze Li @ 2022-04-09  4:25 UTC (permalink / raw)
  To: Jens Axboe; +Cc: phil, linux-kernel, linux-block

On Fri, 8 Apr 2022 06:34:04 -0600
Jens Axboe <axboe@kernel.dk> wrote:

> On 4/8/22 2:42 AM, Enze Li wrote:
> > There is no need to print a list of cdrom entries with blank info
> > when no cdrom device exists.  With this patch applied, we get:
> > 
> > ================================================
> > $ cat /proc/sys/dev/cdrom/info
> > CD-ROM information, Id:cdrom.c 3.20 2003/12/17
> > 
> > No device found.
> > 
> > ================================================  

Hi Jens,

Thanks for your review.

> 
> And what did we get before?

Without the patch, we get:

================================================
$ cat /proc/sys/dev/cdrom/info
CD-ROM information, Id: cdrom.c 3.20 2003/12/17

drive name:	
drive speed:	
drive # of slots:
Can close tray:	
Can open tray:	
Can lock tray:	
Can change speed:
Can select disk:
Can read multisession:
Can read MCN:	
Reports media changed:
Can play audio:	
Can write CD-R:	
Can write CD-RW:
Can read DVD:	
Can write DVD-R:
Can write DVD-RAM:
Can read MRW:	
Can write MRW:	
Can write RAM:	


================================================

> 
> Will this potentially break applications that parse it?
> 

I dunno, is there any way to confirm this thing?  And if this is really
a possibility, does it mean that we cannot make changes?

BTW, could you pls help review the following patch?  I forgot to cc you
and linux-block@list. :)
https://lore.kernel.org/lkml/20220406090337.1116708-1-lienze@kylinos.cn/

Thanks,
Enze

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

* Re: [PATCH] cdrom: do not print info list when there is no cdrom device
  2022-04-09  4:25   ` Enze Li
@ 2022-04-09  8:16     ` Phillip Potter
       [not found]       ` <f74b6933-5357-6b2c-3127-7a3465dadbdf@kylinos.cn>
  0 siblings, 1 reply; 6+ messages in thread
From: Phillip Potter @ 2022-04-09  8:16 UTC (permalink / raw)
  To: Enze Li; +Cc: axboe, linux-kernel, linux-block

On Sat, Apr 09, 2022 at 12:25:30PM +0800, Enze Li wrote:
> On Fri, 8 Apr 2022 06:34:04 -0600
> Jens Axboe <axboe@kernel.dk> wrote:
> 
> > On 4/8/22 2:42 AM, Enze Li wrote:
> > > There is no need to print a list of cdrom entries with blank info
> > > when no cdrom device exists.  With this patch applied, we get:
> > > 
> > > ================================================
> > > $ cat /proc/sys/dev/cdrom/info
> > > CD-ROM information, Id:cdrom.c 3.20 2003/12/17
> > > 
> > > No device found.
> > > 
> > > ================================================  
> 
> Hi Jens,
> 
> Thanks for your review.
> 
> > 
> > And what did we get before?
> 
> Without the patch, we get:
> 
> ================================================
> $ cat /proc/sys/dev/cdrom/info
> CD-ROM information, Id: cdrom.c 3.20 2003/12/17
> 
> drive name:	
> drive speed:	
> drive # of slots:
> Can close tray:	
> Can open tray:	
> Can lock tray:	
> Can change speed:
> Can select disk:
> Can read multisession:
> Can read MCN:	
> Reports media changed:
> Can play audio:	
> Can write CD-R:	
> Can write CD-RW:
> Can read DVD:	
> Can write DVD-R:
> Can write DVD-RAM:
> Can read MRW:	
> Can write MRW:	
> Can write RAM:	
> 
> 
> ================================================
> 
> > 
> > Will this potentially break applications that parse it?
> > 
> 
> I dunno, is there any way to confirm this thing?  And if this is really
> a possibility, does it mean that we cannot make changes?
> 
Sorry, anything that can be parsed from userspace has the potential to
break userspace applications. For that reason, I would have to say I
don't think this patch is suitable. Sure there are times it's
appropriate to change userspace interfaces, but I'd rather err on the
side of caution here. Thanks for the patch though.

Nacked-by: Phillip Potter <phil@philpotter.co.uk>

Regards,
Phil

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

* Re: [PATCH] cdrom: do not print info list when there is no cdrom device
       [not found]       ` <f74b6933-5357-6b2c-3127-7a3465dadbdf@kylinos.cn>
@ 2022-04-11 16:51         ` Jens Axboe
  2022-04-18 21:04           ` Phillip Potter
  0 siblings, 1 reply; 6+ messages in thread
From: Jens Axboe @ 2022-04-11 16:51 UTC (permalink / raw)
  To: Enze Li, Phillip Potter; +Cc: linux-kernel, linux-block

On 4/11/22 2:41 AM, Enze Li wrote:
> 
> On 4/9/22 16:16, Phillip Potter wrote:
>> On Sat, Apr 09, 2022 at 12:25:30PM +0800, Enze Li wrote:
> 
> <snip>
> 
>>> On Fri, 8 Apr 2022 06:34:04 -0600
>>> Jens Axboe <axboe@kernel.dk> wrote:
>>>> Will this potentially break applications that parse it?
>>>>
>>> I dunno, is there any way to confirm this thing?  And if this is really
>>> a possibility, does it mean that we cannot make changes?
>>>
>> Sorry, anything that can be parsed from userspace has the potential to
>> break userspace applications. For that reason, I would have to say I
>> don't think this patch is suitable. Sure there are times it's
>> appropriate to change userspace interfaces, but I'd rather err on the
>> side of caution here. Thanks for the patch though.
>>
>> Nacked-by: Phillip Potter <phil@philpotter.co.uk>
>>
>> Regards,
>> Phil
> 
> Hi Phil,
> 
> Thanks for your review.  I got what you said. ?
> 
> In addition, I noticed that in the source file[1], there is a Todo List there.  I'm quite
> interested in it.  It says:
> ================================================
>   17 To Do List:
>   18 ----------------------------------
>   19
>   20  -- Modify sysctl/proc interface. I plan on having one directory per                 
>   21  drive, with entries for outputing general drive information, and sysctl             
>   22  based tunable parameters such as whether the tray should auto-close for             
>   23  that drive. Suggestions (or patches) for this welcome!
> ================================================
> I'd like to know if the relevant patches are still welcome?
> 
> IIUC, the TODO List says that we need to implement a modification of the
> following form:
> ----------------------------------------------------------------------------------------------------------
> $ tree /proc/sys/dev/cdrom
> /proc/sys/dev/cdrom
> |--sr0--autoclose
> |       |-autoeject
> |       |-check_media
> |       |-debug
> |       |-info
> |       |-lock
> |
> |--sr1--autoclose
> |       |-autoeject
> |       |-check_media
> |       |-debug
> |       |-info
> |       |-lock
> |
> |--sr2 ...
> .
> .
> .
> ----------------------------------------------------------------------------------------------------------
> I would appreciate it if you could give me some advice.

Let's not do that, this advice is perhaps 20 years old. /proc isn't to
be used for anything like that these days.

-- 
Jens Axboe


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

* Re: [PATCH] cdrom: do not print info list when there is no cdrom device
  2022-04-11 16:51         ` Jens Axboe
@ 2022-04-18 21:04           ` Phillip Potter
  0 siblings, 0 replies; 6+ messages in thread
From: Phillip Potter @ 2022-04-18 21:04 UTC (permalink / raw)
  To: Jens Axboe, Enze Li; +Cc: linux-kernel, linux-block

On Mon, Apr 11, 2022 at 10:51:28AM -0600, Jens Axboe wrote:
> >   20  -- Modify sysctl/proc interface. I plan on having one directory per                 
> >   21  drive, with entries for outputing general drive information, and sysctl             
> >   22  based tunable parameters such as whether the tray should auto-close for             
> >   23  that drive. Suggestions (or patches) for this welcome!
> > ================================================
> > I'd like to know if the relevant patches are still welcome?
> > 
> > IIUC, the TODO List says that we need to implement a modification of the
> > following form:
> > ----------------------------------------------------------------------------------------------------------
> > $ tree /proc/sys/dev/cdrom
> > /proc/sys/dev/cdrom
> > |--sr0--autoclose
> > |       |-autoeject
> > |       |-check_media
> > |       |-debug
> > |       |-info
> > |       |-lock
> > |
> > |--sr1--autoclose
> > |       |-autoeject
> > |       |-check_media
> > |       |-debug
> > |       |-info
> > |       |-lock
> > |
> > |--sr2 ...
> > .
> > .
> > .
> > ----------------------------------------------------------------------------------------------------------
> > I would appreciate it if you could give me some advice.
> 
> Let's not do that, this advice is perhaps 20 years old. /proc isn't to
> be used for anything like that these days.
> 
> -- 
> Jens Axboe
>

Hi Both,

I will send a patch alongside others during the next merge window to
remove this TODO section for now. It was part of the initial mainline
git commit (17 years and two days ago), so it (as Jens says) is almost
certainly even older than this.

Regards,
Phil

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

end of thread, other threads:[~2022-04-18 21:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-08  8:42 [PATCH] cdrom: do not print info list when there is no cdrom device Enze Li
2022-04-08 12:34 ` Jens Axboe
2022-04-09  4:25   ` Enze Li
2022-04-09  8:16     ` Phillip Potter
     [not found]       ` <f74b6933-5357-6b2c-3127-7a3465dadbdf@kylinos.cn>
2022-04-11 16:51         ` Jens Axboe
2022-04-18 21:04           ` Phillip Potter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).