[PATCH v2] usbip: tools: Add usbip host driver availability check

Zongmin Zhou posted 1 patch 1 week, 1 day ago
tools/usb/usbip/libsrc/usbip_device_driver.c | 7 +++++--
tools/usb/usbip/libsrc/usbip_host_driver.c   | 8 ++++++--
2 files changed, 11 insertions(+), 4 deletions(-)
[PATCH v2] usbip: tools: Add usbip host driver availability check
Posted by Zongmin Zhou 1 week, 1 day ago
From: Zongmin Zhou <zhouzongmin@kylinos.cn>

Currently, usbip_generic_driver_open() doesn't verify that the required
kernel module (usbip-host or usbip-vudc) is actually loaded.
The function returns success even when no driver is present,
leading to usbipd daemon run success without driver loaded.

So add a check function to ensure usbip host driver has been loaded.

Suggested-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Zongmin Zhou <zhouzongmin@kylinos.cn>
---
Changes in v2:
- Use system calls directly instead of checking sysfs dir.

 tools/usb/usbip/libsrc/usbip_device_driver.c | 7 +++++--
 tools/usb/usbip/libsrc/usbip_host_driver.c   | 8 ++++++--
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/tools/usb/usbip/libsrc/usbip_device_driver.c b/tools/usb/usbip/libsrc/usbip_device_driver.c
index 927a151fa9aa..45ab647ef241 100644
--- a/tools/usb/usbip/libsrc/usbip_device_driver.c
+++ b/tools/usb/usbip/libsrc/usbip_device_driver.c
@@ -136,10 +136,13 @@ static int usbip_device_driver_open(struct usbip_host_driver *hdriver)
 	hdriver->ndevs = 0;
 	INIT_LIST_HEAD(&hdriver->edev_list);
 
-	ret = usbip_generic_driver_open(hdriver);
-	if (ret)
+	if (system("/sbin/lsmod | grep -q usbip_vudc")){
 		err("please load " USBIP_CORE_MOD_NAME ".ko and "
 		    USBIP_DEVICE_DRV_NAME ".ko!");
+		return -1;
+	}
+
+	ret = usbip_generic_driver_open(hdriver);
 
 	return ret;
 }
diff --git a/tools/usb/usbip/libsrc/usbip_host_driver.c b/tools/usb/usbip/libsrc/usbip_host_driver.c
index 573e73ec36bd..f0ac941d4f6e 100644
--- a/tools/usb/usbip/libsrc/usbip_host_driver.c
+++ b/tools/usb/usbip/libsrc/usbip_host_driver.c
@@ -31,10 +31,14 @@ static int usbip_host_driver_open(struct usbip_host_driver *hdriver)
 	hdriver->ndevs = 0;
 	INIT_LIST_HEAD(&hdriver->edev_list);
 
-	ret = usbip_generic_driver_open(hdriver);
-	if (ret)
+	if (system("/sbin/lsmod | grep -q usbip_host")){
 		err("please load " USBIP_CORE_MOD_NAME ".ko and "
 		    USBIP_HOST_DRV_NAME ".ko!");
+		return -1;
+	}
+
+	ret = usbip_generic_driver_open(hdriver);
+
 	return ret;
 }
 
-- 
2.34.1
Re: [PATCH v2] usbip: tools: Add usbip host driver availability check
Posted by Greg KH 1 week, 1 day ago
On Wed, Mar 25, 2026 at 10:26:34AM +0800, Zongmin Zhou wrote:
> From: Zongmin Zhou <zhouzongmin@kylinos.cn>
> 
> Currently, usbip_generic_driver_open() doesn't verify that the required
> kernel module (usbip-host or usbip-vudc) is actually loaded.
> The function returns success even when no driver is present,
> leading to usbipd daemon run success without driver loaded.
> 
> So add a check function to ensure usbip host driver has been loaded.
> 
> Suggested-by: Shuah Khan <skhan@linuxfoundation.org>
> Signed-off-by: Zongmin Zhou <zhouzongmin@kylinos.cn>
> ---
> Changes in v2:
> - Use system calls directly instead of checking sysfs dir.
> 
>  tools/usb/usbip/libsrc/usbip_device_driver.c | 7 +++++--
>  tools/usb/usbip/libsrc/usbip_host_driver.c   | 8 ++++++--
>  2 files changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/usb/usbip/libsrc/usbip_device_driver.c b/tools/usb/usbip/libsrc/usbip_device_driver.c
> index 927a151fa9aa..45ab647ef241 100644
> --- a/tools/usb/usbip/libsrc/usbip_device_driver.c
> +++ b/tools/usb/usbip/libsrc/usbip_device_driver.c
> @@ -136,10 +136,13 @@ static int usbip_device_driver_open(struct usbip_host_driver *hdriver)
>  	hdriver->ndevs = 0;
>  	INIT_LIST_HEAD(&hdriver->edev_list);
>  
> -	ret = usbip_generic_driver_open(hdriver);
> -	if (ret)
> +	if (system("/sbin/lsmod | grep -q usbip_vudc")){

What happens if the module is built into the kernel?

>  		err("please load " USBIP_CORE_MOD_NAME ".ko and "
>  		    USBIP_DEVICE_DRV_NAME ".ko!");
> +		return -1;
> +	}
> +
> +	ret = usbip_generic_driver_open(hdriver);
>  
>  	return ret;
>  }
> diff --git a/tools/usb/usbip/libsrc/usbip_host_driver.c b/tools/usb/usbip/libsrc/usbip_host_driver.c
> index 573e73ec36bd..f0ac941d4f6e 100644
> --- a/tools/usb/usbip/libsrc/usbip_host_driver.c
> +++ b/tools/usb/usbip/libsrc/usbip_host_driver.c
> @@ -31,10 +31,14 @@ static int usbip_host_driver_open(struct usbip_host_driver *hdriver)
>  	hdriver->ndevs = 0;
>  	INIT_LIST_HEAD(&hdriver->edev_list);
>  
> -	ret = usbip_generic_driver_open(hdriver);
> -	if (ret)
> +	if (system("/sbin/lsmod | grep -q usbip_host")){

Same here, what happens if it is built in?

thanks,

greg k-h
Re: [PATCH v2] usbip: tools: Add usbip host driver availability check
Posted by Zongmin Zhou 1 week ago
On 2026/3/25 16:58, Greg KH wrote:
> On Wed, Mar 25, 2026 at 10:26:34AM +0800, Zongmin Zhou wrote:
>> From: Zongmin Zhou <zhouzongmin@kylinos.cn>
>>
>> Currently, usbip_generic_driver_open() doesn't verify that the required
>> kernel module (usbip-host or usbip-vudc) is actually loaded.
>> The function returns success even when no driver is present,
>> leading to usbipd daemon run success without driver loaded.
>>
>> So add a check function to ensure usbip host driver has been loaded.
>>
>> Suggested-by: Shuah Khan <skhan@linuxfoundation.org>
>> Signed-off-by: Zongmin Zhou <zhouzongmin@kylinos.cn>
>> ---
>> Changes in v2:
>> - Use system calls directly instead of checking sysfs dir.
>>
>>   tools/usb/usbip/libsrc/usbip_device_driver.c | 7 +++++--
>>   tools/usb/usbip/libsrc/usbip_host_driver.c   | 8 ++++++--
>>   2 files changed, 11 insertions(+), 4 deletions(-)
>>
>> diff --git a/tools/usb/usbip/libsrc/usbip_device_driver.c b/tools/usb/usbip/libsrc/usbip_device_driver.c
>> index 927a151fa9aa..45ab647ef241 100644
>> --- a/tools/usb/usbip/libsrc/usbip_device_driver.c
>> +++ b/tools/usb/usbip/libsrc/usbip_device_driver.c
>> @@ -136,10 +136,13 @@ static int usbip_device_driver_open(struct usbip_host_driver *hdriver)
>>   	hdriver->ndevs = 0;
>>   	INIT_LIST_HEAD(&hdriver->edev_list);
>>   
>> -	ret = usbip_generic_driver_open(hdriver);
>> -	if (ret)
>> +	if (system("/sbin/lsmod | grep -q usbip_vudc")){
> What happens if the module is built into the kernel?
>
>>   		err("please load " USBIP_CORE_MOD_NAME ".ko and "
>>   		    USBIP_DEVICE_DRV_NAME ".ko!");
>> +		return -1;
>> +	}
>> +
>> +	ret = usbip_generic_driver_open(hdriver);
>>   
>>   	return ret;
>>   }
>> diff --git a/tools/usb/usbip/libsrc/usbip_host_driver.c b/tools/usb/usbip/libsrc/usbip_host_driver.c
>> index 573e73ec36bd..f0ac941d4f6e 100644
>> --- a/tools/usb/usbip/libsrc/usbip_host_driver.c
>> +++ b/tools/usb/usbip/libsrc/usbip_host_driver.c
>> @@ -31,10 +31,14 @@ static int usbip_host_driver_open(struct usbip_host_driver *hdriver)
>>   	hdriver->ndevs = 0;
>>   	INIT_LIST_HEAD(&hdriver->edev_list);
>>   
>> -	ret = usbip_generic_driver_open(hdriver);
>> -	if (ret)
>> +	if (system("/sbin/lsmod | grep -q usbip_host")){
> Same here, what happens if it is built in?
Thank you for pointing this out.
I apologize for not considering the built-in module case.

You are right that using lsmod | grep would incorrectly fail when 
usbip_host is built into the kernel (CONFIG_USBIP_HOST=y).
Usbip has always been built as a loadable module (.ko) by default, which 
led to this oversight.

To address this issue, would the following approach be acceptable?
1. Uses /sys/module/usbip_host to check wehther had been loaded, which 
exists for both loadable modules and built-in drivers.
2. Attempts to load the module via modprobe if it is not already loaded.

for example:
static int probe_usbip_host_driver(void)
{
      struct stat st;
      return !stat("/sys/module/usbip_host", &st);
}

static int usbip_host_driver_open(struct usbip_host_driver *hdriver)
{
      // 1. Check if driver is already loaded/built-in
      if (!probe_usbip_host_driver()) {
          // 2. Try to load the module
          system("/sbin/modprobe usbip-host > /dev/null 2>&1");
         // 3. Check again
           if (!probe_usbip_host_driver()) {
               err("please load " USBIP_CORE_MOD_NAME ".ko and "
                   USBIP_HOST_DRV_NAME ".ko!");
               return -1;
}
}

       // Continue with normal flow...
       ret = usbip_generic_driver_open(hdriver);
       return ret;
}

Does this look reasonable to you? I would be happy to submit a v3 patch 
with this approach if you agree.
>
> thanks,
>
> greg k-h

Re: [PATCH v2] usbip: tools: Add usbip host driver availability check
Posted by Greg KH 1 week ago
On Thu, Mar 26, 2026 at 11:10:02AM +0800, Zongmin Zhou wrote:
> 
> On 2026/3/25 16:58, Greg KH wrote:
> > On Wed, Mar 25, 2026 at 10:26:34AM +0800, Zongmin Zhou wrote:
> > > From: Zongmin Zhou <zhouzongmin@kylinos.cn>
> > > 
> > > Currently, usbip_generic_driver_open() doesn't verify that the required
> > > kernel module (usbip-host or usbip-vudc) is actually loaded.
> > > The function returns success even when no driver is present,
> > > leading to usbipd daemon run success without driver loaded.
> > > 
> > > So add a check function to ensure usbip host driver has been loaded.
> > > 
> > > Suggested-by: Shuah Khan <skhan@linuxfoundation.org>
> > > Signed-off-by: Zongmin Zhou <zhouzongmin@kylinos.cn>
> > > ---
> > > Changes in v2:
> > > - Use system calls directly instead of checking sysfs dir.
> > > 
> > >   tools/usb/usbip/libsrc/usbip_device_driver.c | 7 +++++--
> > >   tools/usb/usbip/libsrc/usbip_host_driver.c   | 8 ++++++--
> > >   2 files changed, 11 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/tools/usb/usbip/libsrc/usbip_device_driver.c b/tools/usb/usbip/libsrc/usbip_device_driver.c
> > > index 927a151fa9aa..45ab647ef241 100644
> > > --- a/tools/usb/usbip/libsrc/usbip_device_driver.c
> > > +++ b/tools/usb/usbip/libsrc/usbip_device_driver.c
> > > @@ -136,10 +136,13 @@ static int usbip_device_driver_open(struct usbip_host_driver *hdriver)
> > >   	hdriver->ndevs = 0;
> > >   	INIT_LIST_HEAD(&hdriver->edev_list);
> > > -	ret = usbip_generic_driver_open(hdriver);
> > > -	if (ret)
> > > +	if (system("/sbin/lsmod | grep -q usbip_vudc")){
> > What happens if the module is built into the kernel?
> > 
> > >   		err("please load " USBIP_CORE_MOD_NAME ".ko and "
> > >   		    USBIP_DEVICE_DRV_NAME ".ko!");
> > > +		return -1;
> > > +	}
> > > +
> > > +	ret = usbip_generic_driver_open(hdriver);
> > >   	return ret;
> > >   }
> > > diff --git a/tools/usb/usbip/libsrc/usbip_host_driver.c b/tools/usb/usbip/libsrc/usbip_host_driver.c
> > > index 573e73ec36bd..f0ac941d4f6e 100644
> > > --- a/tools/usb/usbip/libsrc/usbip_host_driver.c
> > > +++ b/tools/usb/usbip/libsrc/usbip_host_driver.c
> > > @@ -31,10 +31,14 @@ static int usbip_host_driver_open(struct usbip_host_driver *hdriver)
> > >   	hdriver->ndevs = 0;
> > >   	INIT_LIST_HEAD(&hdriver->edev_list);
> > > -	ret = usbip_generic_driver_open(hdriver);
> > > -	if (ret)
> > > +	if (system("/sbin/lsmod | grep -q usbip_host")){
> > Same here, what happens if it is built in?
> Thank you for pointing this out.
> I apologize for not considering the built-in module case.
> 
> You are right that using lsmod | grep would incorrectly fail when usbip_host
> is built into the kernel (CONFIG_USBIP_HOST=y).
> Usbip has always been built as a loadable module (.ko) by default, which led
> to this oversight.
> 
> To address this issue, would the following approach be acceptable?

Wait, what "issue" are you trying to fix here?  Why can't you just check
for opening the correct device node when the host opens the file and if
that fails, report an error?  Doesn't that happen today already?

> 1. Uses /sys/module/usbip_host to check wehther had been loaded, which
> exists for both loadable modules and built-in drivers.
> 2. Attempts to load the module via modprobe if it is not already loaded.

Don't do module autoloading, that might surprise users that previously
were not expecting it.

thanks,

greg k-h
Re: [PATCH v2] usbip: tools: Add usbip host driver availability check
Posted by Shuah Khan 1 week ago
On 3/26/26 02:43, Greg KH wrote:
> On Thu, Mar 26, 2026 at 11:10:02AM +0800, Zongmin Zhou wrote:
>>
>> On 2026/3/25 16:58, Greg KH wrote:
>>> On Wed, Mar 25, 2026 at 10:26:34AM +0800, Zongmin Zhou wrote:
>>>> From: Zongmin Zhou <zhouzongmin@kylinos.cn>
>>>>
>>>> Currently, usbip_generic_driver_open() doesn't verify that the required
>>>> kernel module (usbip-host or usbip-vudc) is actually loaded.
>>>> The function returns success even when no driver is present,
>>>> leading to usbipd daemon run success without driver loaded.
>>>>
>>>> So add a check function to ensure usbip host driver has been loaded.
>>>>
>>>> Suggested-by: Shuah Khan <skhan@linuxfoundation.org>
>>>> Signed-off-by: Zongmin Zhou <zhouzongmin@kylinos.cn>
>>>> ---
>>>> Changes in v2:
>>>> - Use system calls directly instead of checking sysfs dir.
>>>>
>>>>    tools/usb/usbip/libsrc/usbip_device_driver.c | 7 +++++--
>>>>    tools/usb/usbip/libsrc/usbip_host_driver.c   | 8 ++++++--
>>>>    2 files changed, 11 insertions(+), 4 deletions(-)
>>>>
>>>> diff --git a/tools/usb/usbip/libsrc/usbip_device_driver.c b/tools/usb/usbip/libsrc/usbip_device_driver.c
>>>> index 927a151fa9aa..45ab647ef241 100644
>>>> --- a/tools/usb/usbip/libsrc/usbip_device_driver.c
>>>> +++ b/tools/usb/usbip/libsrc/usbip_device_driver.c
>>>> @@ -136,10 +136,13 @@ static int usbip_device_driver_open(struct usbip_host_driver *hdriver)
>>>>    	hdriver->ndevs = 0;
>>>>    	INIT_LIST_HEAD(&hdriver->edev_list);
>>>> -	ret = usbip_generic_driver_open(hdriver);
>>>> -	if (ret)
>>>> +	if (system("/sbin/lsmod | grep -q usbip_vudc")){
>>> What happens if the module is built into the kernel?
>>>
>>>>    		err("please load " USBIP_CORE_MOD_NAME ".ko and "
>>>>    		    USBIP_DEVICE_DRV_NAME ".ko!");
>>>> +		return -1;
>>>> +	}
>>>> +
>>>> +	ret = usbip_generic_driver_open(hdriver);
>>>>    	return ret;
>>>>    }
>>>> diff --git a/tools/usb/usbip/libsrc/usbip_host_driver.c b/tools/usb/usbip/libsrc/usbip_host_driver.c
>>>> index 573e73ec36bd..f0ac941d4f6e 100644
>>>> --- a/tools/usb/usbip/libsrc/usbip_host_driver.c
>>>> +++ b/tools/usb/usbip/libsrc/usbip_host_driver.c
>>>> @@ -31,10 +31,14 @@ static int usbip_host_driver_open(struct usbip_host_driver *hdriver)
>>>>    	hdriver->ndevs = 0;
>>>>    	INIT_LIST_HEAD(&hdriver->edev_list);
>>>> -	ret = usbip_generic_driver_open(hdriver);
>>>> -	if (ret)
>>>> +	if (system("/sbin/lsmod | grep -q usbip_host")){
>>> Same here, what happens if it is built in?
>> Thank you for pointing this out.
>> I apologize for not considering the built-in module case.
>>
>> You are right that using lsmod | grep would incorrectly fail when usbip_host
>> is built into the kernel (CONFIG_USBIP_HOST=y).
>> Usbip has always been built as a loadable module (.ko) by default, which led
>> to this oversight.
>>
>> To address this issue, would the following approach be acceptable?
> 
> Wait, what "issue" are you trying to fix here?  Why can't you just check
> for opening the correct device node when the host opens the file and if
> that fails, report an error?  Doesn't that happen today already?
> 

The problem Zongmin is trying fix ish when usbipd starts, it looks for
exported if any - if it doesn't find any it assumes there aren't any
exported and doesn't detect that usbip_host driver isn't loaded.

refresh_exported_devices() doesn't have the logic and it shouldn't
include that logic because this hook is called periodically to
refresh the list of exported devices. Starting usbipd and loading
the driver are distinct steps and without any dependencies.

This patch he is trying to add that detection so a message can be printed
to say "load the driver".

A message can be added easily to cover two cases:

1. usbip_host driver isn't loaded
2. There are no exported devices.

refresh_exported_devices() will not find any devices in both
of the above scenarios. It isn't an error if it can't find
any exported devices.

An informational message when refresh_exported_devices()
when it doesn't find any devices could help users.

Zongmin,

Would adding a message that says
"Check if usbip_host driver is loaded or export devices"
solve the problem of hard to debug problem you are addressing here?

thanks,
-- Shuah
Re: [PATCH v2] usbip: tools: Add usbip host driver availability check
Posted by Zongmin Zhou 6 days, 16 hours ago
On 2026/3/27 02:43, Shuah Khan wrote:
> On 3/26/26 02:43, Greg KH wrote:
>> On Thu, Mar 26, 2026 at 11:10:02AM +0800, Zongmin Zhou wrote:
>>>
>>> On 2026/3/25 16:58, Greg KH wrote:
>>>> On Wed, Mar 25, 2026 at 10:26:34AM +0800, Zongmin Zhou wrote:
>>>>> From: Zongmin Zhou <zhouzongmin@kylinos.cn>
>>>>>
>>>>> Currently, usbip_generic_driver_open() doesn't verify that the 
>>>>> required
>>>>> kernel module (usbip-host or usbip-vudc) is actually loaded.
>>>>> The function returns success even when no driver is present,
>>>>> leading to usbipd daemon run success without driver loaded.
>>>>>
>>>>> So add a check function to ensure usbip host driver has been loaded.
>>>>>
>>>>> Suggested-by: Shuah Khan <skhan@linuxfoundation.org>
>>>>> Signed-off-by: Zongmin Zhou <zhouzongmin@kylinos.cn>
>>>>> ---
>>>>> Changes in v2:
>>>>> - Use system calls directly instead of checking sysfs dir.
>>>>>
>>>>>    tools/usb/usbip/libsrc/usbip_device_driver.c | 7 +++++--
>>>>>    tools/usb/usbip/libsrc/usbip_host_driver.c   | 8 ++++++--
>>>>>    2 files changed, 11 insertions(+), 4 deletions(-)
>>>>>
>>>>> diff --git a/tools/usb/usbip/libsrc/usbip_device_driver.c 
>>>>> b/tools/usb/usbip/libsrc/usbip_device_driver.c
>>>>> index 927a151fa9aa..45ab647ef241 100644
>>>>> --- a/tools/usb/usbip/libsrc/usbip_device_driver.c
>>>>> +++ b/tools/usb/usbip/libsrc/usbip_device_driver.c
>>>>> @@ -136,10 +136,13 @@ static int usbip_device_driver_open(struct 
>>>>> usbip_host_driver *hdriver)
>>>>>        hdriver->ndevs = 0;
>>>>>        INIT_LIST_HEAD(&hdriver->edev_list);
>>>>> -    ret = usbip_generic_driver_open(hdriver);
>>>>> -    if (ret)
>>>>> +    if (system("/sbin/lsmod | grep -q usbip_vudc")){
>>>> What happens if the module is built into the kernel?
>>>>
>>>>>            err("please load " USBIP_CORE_MOD_NAME ".ko and "
>>>>>                USBIP_DEVICE_DRV_NAME ".ko!");
>>>>> +        return -1;
>>>>> +    }
>>>>> +
>>>>> +    ret = usbip_generic_driver_open(hdriver);
>>>>>        return ret;
>>>>>    }
>>>>> diff --git a/tools/usb/usbip/libsrc/usbip_host_driver.c 
>>>>> b/tools/usb/usbip/libsrc/usbip_host_driver.c
>>>>> index 573e73ec36bd..f0ac941d4f6e 100644
>>>>> --- a/tools/usb/usbip/libsrc/usbip_host_driver.c
>>>>> +++ b/tools/usb/usbip/libsrc/usbip_host_driver.c
>>>>> @@ -31,10 +31,14 @@ static int usbip_host_driver_open(struct 
>>>>> usbip_host_driver *hdriver)
>>>>>        hdriver->ndevs = 0;
>>>>>        INIT_LIST_HEAD(&hdriver->edev_list);
>>>>> -    ret = usbip_generic_driver_open(hdriver);
>>>>> -    if (ret)
>>>>> +    if (system("/sbin/lsmod | grep -q usbip_host")){
>>>> Same here, what happens if it is built in?
>>> Thank you for pointing this out.
>>> I apologize for not considering the built-in module case.
>>>
>>> You are right that using lsmod | grep would incorrectly fail when 
>>> usbip_host
>>> is built into the kernel (CONFIG_USBIP_HOST=y).
>>> Usbip has always been built as a loadable module (.ko) by default, 
>>> which led
>>> to this oversight.
>>>
>>> To address this issue, would the following approach be acceptable?
>>
>> Wait, what "issue" are you trying to fix here?  Why can't you just check
>> for opening the correct device node when the host opens the file and if
>> that fails, report an error?  Doesn't that happen today already?
>>
>
> The problem Zongmin is trying fix ish when usbipd starts, it looks for
> exported if any - if it doesn't find any it assumes there aren't any
> exported and doesn't detect that usbip_host driver isn't loaded.
>
> refresh_exported_devices() doesn't have the logic and it shouldn't
> include that logic because this hook is called periodically to
> refresh the list of exported devices. Starting usbipd and loading
> the driver are distinct steps and without any dependencies.
>
> This patch he is trying to add that detection so a message can be printed
> to say "load the driver".
>
> A message can be added easily to cover two cases:
>
> 1. usbip_host driver isn't loaded
> 2. There are no exported devices.
>
> refresh_exported_devices() will not find any devices in both
> of the above scenarios. It isn't an error if it can't find
> any exported devices.
>
> An informational message when refresh_exported_devices()
> when it doesn't find any devices could help users.
>
> Zongmin,
>
> Would adding a message that says
> "Check if usbip_host driver is loaded or export devices"
> solve the problem of hard to debug problem you are addressing here?
>
Shuah,

Your suggestion makes sense.
Adding an informational message when no devices are found would be a simple
and clean solution that helps users debug without being intrusive.

However, I plan to add the info() message in usbip_generic_driver_open() 
instead of
refresh_exported_devices(), because:
- usbip_generic_driver_open() is called only once at initialization.
- refresh_exported_devices() is called periodically to refresh the 
exported device list.
- When the server has no exported devices, having zero devices
   is normal and not worth frequent info messages.

Theoretically, we only need to prompt once at startup. Is my 
understanding correct?

I'll also remove the existing error messages like below,
since they cannot accurately determine whether the driver is loaded:

if (ret)
     err("please load " USBIP_CORE_MOD_NAME ".ko and "
         USBIP_HOST_DRV_NAME ".ko!");

Does this approach look acceptable?

Best regards,
--Zongmin Zhou
> thanks,
> -- Shuah

Re: [PATCH v2] usbip: tools: Add usbip host driver availability check
Posted by Shuah Khan 6 days, 7 hours ago
On 3/27/26 02:39, Zongmin Zhou wrote:
> 
> On 2026/3/27 02:43, Shuah Khan wrote:
>> On 3/26/26 02:43, Greg KH wrote:

[removed text]

>>
>> The problem Zongmin is trying fix ish when usbipd starts, it looks for
>> exported if any - if it doesn't find any it assumes there aren't any
>> exported and doesn't detect that usbip_host driver isn't loaded.
>>
>> refresh_exported_devices() doesn't have the logic and it shouldn't
>> include that logic because this hook is called periodically to
>> refresh the list of exported devices. Starting usbipd and loading
>> the driver are distinct steps and without any dependencies.
>>
>> This patch he is trying to add that detection so a message can be printed
>> to say "load the driver".
>>
>> A message can be added easily to cover two cases:
>>
>> 1. usbip_host driver isn't loaded
>> 2. There are no exported devices.
>>
>> refresh_exported_devices() will not find any devices in both
>> of the above scenarios. It isn't an error if it can't find
>> any exported devices.
>>
>> An informational message when refresh_exported_devices()
>> when it doesn't find any devices could help users.
>>
>> Zongmin,
>>
>> Would adding a message that says
>> "Check if usbip_host driver is loaded or export devices"
>> solve the problem of hard to debug problem you are addressing here?
>>
> Shuah,
> 
> Your suggestion makes sense.
> Adding an informational message when no devices are found would be a simple
> and clean solution that helps users debug without being intrusive.
> 
> However, I plan to add the info() message in usbip_generic_driver_open() instead of
> refresh_exported_devices(), because:
> - usbip_generic_driver_open() is called only once at initialization.
> - refresh_exported_devices() is called periodically to refresh the exported device list.

refresh_exported_devices() isn't called periodically - it is called
from usbip_host_driver op: refresh_device_list and it will be called
whenever usbipd (host side) calls it whenever it receives a request from
user-space via process_request()

For example running "usbip list -l" command will trigger a run of
refresh_exported_devices() via usbip_host_driver op: refresh_device_list

I don't think it will that noisy to add a message to refresh_exported_devices()
when device list is zero. Currently the logic doesn't detect device list zero.
You have add that condition to print informational message.


> - When the server has no exported devices, having zero devices
>    is normal and not worth frequent info messages.

That is correct. Zero exported devices isn't an error and this could
persist until devices are exported.

> 
> Theoretically, we only need to prompt once at startup. Is my understanding correct?> > I'll also remove the existing error messages like below,
> since they cannot accurately determine whether the driver is loaded:
> 
> if (ret)
>      err("please load " USBIP_CORE_MOD_NAME ".ko and "
>          USBIP_HOST_DRV_NAME ".ko!");

Leave this one alone, because it gets called from a couple of places.

thanks,
-- Shuah
Re: [PATCH v2] usbip: tools: Add usbip host driver availability check
Posted by Shuah Khan 6 days, 7 hours ago
On 3/27/26 11:51, Shuah Khan wrote:
> On 3/27/26 02:39, Zongmin Zhou wrote:
>>
>> On 2026/3/27 02:43, Shuah Khan wrote:
>>> On 3/26/26 02:43, Greg KH wrote:
> 
> [removed text]
> 
>>>
>>> The problem Zongmin is trying fix ish when usbipd starts, it looks for
>>> exported if any - if it doesn't find any it assumes there aren't any
>>> exported and doesn't detect that usbip_host driver isn't loaded.
>>>
>>> refresh_exported_devices() doesn't have the logic and it shouldn't
>>> include that logic because this hook is called periodically to
>>> refresh the list of exported devices. Starting usbipd and loading
>>> the driver are distinct steps and without any dependencies.
>>>
>>> This patch he is trying to add that detection so a message can be printed
>>> to say "load the driver".
>>>
>>> A message can be added easily to cover two cases:
>>>
>>> 1. usbip_host driver isn't loaded
>>> 2. There are no exported devices.
>>>
>>> refresh_exported_devices() will not find any devices in both
>>> of the above scenarios. It isn't an error if it can't find
>>> any exported devices.
>>>
>>> An informational message when refresh_exported_devices()
>>> when it doesn't find any devices could help users.
>>>
>>> Zongmin,
>>>
>>> Would adding a message that says
>>> "Check if usbip_host driver is loaded or export devices"
>>> solve the problem of hard to debug problem you are addressing here?
>>>
>> Shuah,
>>
>> Your suggestion makes sense.
>> Adding an informational message when no devices are found would be a simple
>> and clean solution that helps users debug without being intrusive.
>>
>> However, I plan to add the info() message in usbip_generic_driver_open() instead of
>> refresh_exported_devices(), because:
>> - usbip_generic_driver_open() is called only once at initialization.
>> - refresh_exported_devices() is called periodically to refresh the exported device list.
> 
> refresh_exported_devices() isn't called periodically - it is called
> from usbip_host_driver op: refresh_device_list and it will be called
> whenever usbipd (host side) calls it whenever it receives a request from
> user-space via process_request()
> 
> For example running "usbip list -l" command will trigger a run of
> refresh_exported_devices() via usbip_host_driver op: refresh_device_list
> 
> I don't think it will that noisy to add a message to refresh_exported_devices()
> when device list is zero. Currently the logic doesn't detect device list zero.
> You have add that condition to print informational message.
> 
> 
>> - When the server has no exported devices, having zero devices
>>    is normal and not worth frequent info messages.
> 
> That is correct. Zero exported devices isn't an error and this could
> persist until devices are exported.
> 
>>
>> Theoretically, we only need to prompt once at startup. Is my understanding correct?> > I'll also remove the existing error messages like below,
>> since they cannot accurately determine whether the driver is loaded:
>>
>> if (ret)
>>      err("please load " USBIP_CORE_MOD_NAME ".ko and "
>>          USBIP_HOST_DRV_NAME ".ko!");
> 
> Leave this one alone, because it gets called from a couple of places.
> 

Better yet, why not change the usbip instead - usbip_list for example.
This is the one that prints the device list and the change can be made
there when the list is zero to say, "Check if driver is loaded and
exported devices"

thanks,
-- Shuah
Re: [PATCH v2] usbip: tools: Add usbip host driver availability check
Posted by Zongmin Zhou 3 days, 22 hours ago
On 2026/3/28 02:29, Shuah Khan wrote:
> On 3/27/26 11:51, Shuah Khan wrote:
>> On 3/27/26 02:39, Zongmin Zhou wrote:
>>>
>>> On 2026/3/27 02:43, Shuah Khan wrote:
>>>> On 3/26/26 02:43, Greg KH wrote:
>>
>> [removed text]
>>
>>>>
>>>> The problem Zongmin is trying fix ish when usbipd starts, it looks for
>>>> exported if any - if it doesn't find any it assumes there aren't any
>>>> exported and doesn't detect that usbip_host driver isn't loaded.
>>>>
>>>> refresh_exported_devices() doesn't have the logic and it shouldn't
>>>> include that logic because this hook is called periodically to
>>>> refresh the list of exported devices. Starting usbipd and loading
>>>> the driver are distinct steps and without any dependencies.
>>>>
>>>> This patch he is trying to add that detection so a message can be 
>>>> printed
>>>> to say "load the driver".
>>>>
>>>> A message can be added easily to cover two cases:
>>>>
>>>> 1. usbip_host driver isn't loaded
>>>> 2. There are no exported devices.
>>>>
>>>> refresh_exported_devices() will not find any devices in both
>>>> of the above scenarios. It isn't an error if it can't find
>>>> any exported devices.
>>>>
>>>> An informational message when refresh_exported_devices()
>>>> when it doesn't find any devices could help users.
>>>>
>>>> Zongmin,
>>>>
>>>> Would adding a message that says
>>>> "Check if usbip_host driver is loaded or export devices"
>>>> solve the problem of hard to debug problem you are addressing here?
>>>>
>>> Shuah,
>>>
>>> Your suggestion makes sense.
>>> Adding an informational message when no devices are found would be a 
>>> simple
>>> and clean solution that helps users debug without being intrusive.
>>>
>>> However, I plan to add the info() message in 
>>> usbip_generic_driver_open() instead of
>>> refresh_exported_devices(), because:
>>> - usbip_generic_driver_open() is called only once at initialization.
>>> - refresh_exported_devices() is called periodically to refresh the 
>>> exported device list.
>>
>> refresh_exported_devices() isn't called periodically - it is called
>> from usbip_host_driver op: refresh_device_list and it will be called
>> whenever usbipd (host side) calls it whenever it receives a request from
>> user-space via process_request()
>>
>> For example running "usbip list -l" command will trigger a run of
>> refresh_exported_devices() via usbip_host_driver op: refresh_device_list
>>
>> I don't think it will that noisy to add a message to 
>> refresh_exported_devices()
>> when device list is zero. Currently the logic doesn't detect device 
>> list zero.
>> You have add that condition to print informational message.
>>
>>
>>> - When the server has no exported devices, having zero devices
>>>    is normal and not worth frequent info messages.
>>
>> That is correct. Zero exported devices isn't an error and this could
>> persist until devices are exported.
>>
>>>
>>> Theoretically, we only need to prompt once at startup. Is my 
>>> understanding correct?> > I'll also remove the existing error 
>>> messages like below,
>>> since they cannot accurately determine whether the driver is loaded:
>>>
>>> if (ret)
>>>      err("please load " USBIP_CORE_MOD_NAME ".ko and "
>>>          USBIP_HOST_DRV_NAME ".ko!");
>>
>> Leave this one alone, because it gets called from a couple of places.
In usbip_generic_driver_open(), the only path that triggers this message 
is a failure of udev_new().
This function fails due to system-level issues like memory exhaustion, 
not because usbip driver module is missing.

Furthermore, since refresh_exported_devices() doesn't practically return 
an error here,
the message is never seen during actual driver loading failures.
So I think it’s better to remove this inaccurate hint to avoid confusing 
the users.

This is the reason why I previously wanted to remove it.
>>
>
> Better yet, why not change the usbip instead - usbip_list for example.
> This is the one that prints the device list and the change can be made
> there when the list is zero to say, "Check if driver is loaded and
> exported devices"
I think placing the check/message in refresh_exported_devices() would be 
more effective.
This function covers all scenarios where the device list is refreshed, 
including:
usbipd startup, usbip list -r, and usbip attach operations.

This way, users receive helpful feedback automatically without needing 
to explicitly run usbip list -r.
>
> thanks,
> -- Shuah

Re: [PATCH v2] usbip: tools: Add usbip host driver availability check
Posted by Shuah Khan 3 days, 8 hours ago
On 3/29/26 21:10, Zongmin Zhou wrote:
> 
> On 2026/3/28 02:29, Shuah Khan wrote:
>> On 3/27/26 11:51, Shuah Khan wrote:
>>> On 3/27/26 02:39, Zongmin Zhou wrote:
>>>>
>>>> On 2026/3/27 02:43, Shuah Khan wrote:
>>>>> On 3/26/26 02:43, Greg KH wrote:
>>>
>>> [removed text]
>>>
>>>>>
>>>>> The problem Zongmin is trying fix ish when usbipd starts, it looks for
>>>>> exported if any - if it doesn't find any it assumes there aren't any
>>>>> exported and doesn't detect that usbip_host driver isn't loaded.
>>>>>
>>>>> refresh_exported_devices() doesn't have the logic and it shouldn't
>>>>> include that logic because this hook is called periodically to
>>>>> refresh the list of exported devices. Starting usbipd and loading
>>>>> the driver are distinct steps and without any dependencies.
>>>>>
>>>>> This patch he is trying to add that detection so a message can be printed
>>>>> to say "load the driver".
>>>>>
>>>>> A message can be added easily to cover two cases:
>>>>>
>>>>> 1. usbip_host driver isn't loaded
>>>>> 2. There are no exported devices.
>>>>>
>>>>> refresh_exported_devices() will not find any devices in both
>>>>> of the above scenarios. It isn't an error if it can't find
>>>>> any exported devices.
>>>>>
>>>>> An informational message when refresh_exported_devices()
>>>>> when it doesn't find any devices could help users.
>>>>>
>>>>> Zongmin,
>>>>>
>>>>> Would adding a message that says
>>>>> "Check if usbip_host driver is loaded or export devices"
>>>>> solve the problem of hard to debug problem you are addressing here?
>>>>>
>>>> Shuah,
>>>>
>>>> Your suggestion makes sense.
>>>> Adding an informational message when no devices are found would be a simple
>>>> and clean solution that helps users debug without being intrusive.
>>>>
>>>> However, I plan to add the info() message in usbip_generic_driver_open() instead of
>>>> refresh_exported_devices(), because:
>>>> - usbip_generic_driver_open() is called only once at initialization.
>>>> - refresh_exported_devices() is called periodically to refresh the exported device list.
>>>
>>> refresh_exported_devices() isn't called periodically - it is called
>>> from usbip_host_driver op: refresh_device_list and it will be called
>>> whenever usbipd (host side) calls it whenever it receives a request from
>>> user-space via process_request()
>>>
>>> For example running "usbip list -l" command will trigger a run of
>>> refresh_exported_devices() via usbip_host_driver op: refresh_device_list
>>>
>>> I don't think it will that noisy to add a message to refresh_exported_devices()
>>> when device list is zero. Currently the logic doesn't detect device list zero.
>>> You have add that condition to print informational message.
>>>
>>>
>>>> - When the server has no exported devices, having zero devices
>>>>    is normal and not worth frequent info messages.
>>>
>>> That is correct. Zero exported devices isn't an error and this could
>>> persist until devices are exported.
>>>
>>>>
>>>> Theoretically, we only need to prompt once at startup. Is my understanding correct?> > I'll also remove the existing error messages like below,
>>>> since they cannot accurately determine whether the driver is loaded:
>>>>
>>>> if (ret)
>>>>      err("please load " USBIP_CORE_MOD_NAME ".ko and "
>>>>          USBIP_HOST_DRV_NAME ".ko!");
>>>
>>> Leave this one alone, because it gets called from a couple of places.
> In usbip_generic_driver_open(), the only path that triggers this message is a failure of udev_new().
> This function fails due to system-level issues like memory exhaustion, not because usbip driver module is missing.
> 
> Furthermore, since refresh_exported_devices() doesn't practically return an error here,
> the message is never seen during actual driver loading failures.
> So I think it’s better to remove this inaccurate hint to avoid confusing the users.
> 
> This is the reason why I previously wanted to remove it.
>>>
>>
>> Better yet, why not change the usbip instead - usbip_list for example.
>> This is the one that prints the device list and the change can be made
>> there when the list is zero to say, "Check if driver is loaded and
>> exported devices"
> I think placing the check/message in refresh_exported_devices() would be more effective.
> This function covers all scenarios where the device list is refreshed, including:
> usbipd startup, usbip list -r, and usbip attach operations.

Right changing refresh_exported_devices() covers all cases. Think about the
following scenarios:

- Where will this message get printed when usbipd is started on the console and in
   background?

- Where will this message get printed when user runs various usbip list commands?

Ideally these commands should tell the user what happened without looking
at daemon logs.

thanks,
-- Shuah
[PATCH v3] usbip: tools: add hint when no exported devices are found
Posted by Zongmin Zhou 2 days, 15 hours ago
From: Zongmin Zhou <zhouzongmin@kylinos.cn>

When refresh_exported_devices() finds no devices, it's helpful to
inform users about potential causes. This could be due to:

1. The usbip driver module is not loaded.
2. No devices have been exported yet.

Add an informational message to guide users when ndevs == 0.

Message visibility by scenario:
- usbipd (console mode): Show on console/serial, this allows instant
  visibility for debugging.
- usbipd -D (daemon mode): Message logged to syslog, can keep logs for
  later traceability in production. Also can use "journalctl -f" to
  trace on console.

Suggested-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Zongmin Zhou <zhouzongmin@kylinos.cn>
---
Changes in v3:
- Just add an informational message when no devices are found.
Changes in v2:
- Use system calls directly instead of checking sysfs dir.

 tools/usb/usbip/libsrc/usbip_host_common.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tools/usb/usbip/libsrc/usbip_host_common.c b/tools/usb/usbip/libsrc/usbip_host_common.c
index ca78aa368476..cd92baee310c 100644
--- a/tools/usb/usbip/libsrc/usbip_host_common.c
+++ b/tools/usb/usbip/libsrc/usbip_host_common.c
@@ -149,6 +149,13 @@ static int refresh_exported_devices(struct usbip_host_driver *hdriver)
 		}
 	}
 
+	if (hdriver->ndevs == 0) {
+		if (!strcmp(hdriver->udev_subsystem, "usb"))
+			info("Please check if %s driver is loaded or export devices.",USBIP_HOST_DRV_NAME);
+		else
+			info("Please check if %s driver is loaded or export devices.",USBIP_DEVICE_DRV_NAME);
+	}
+
 	return 0;
 }
 
-- 
2.34.1
Re: [PATCH v3] usbip: tools: add hint when no exported devices are found
Posted by Shuah Khan 2 days, 1 hour ago
On 3/31/26 03:58, Zongmin Zhou wrote:
> From: Zongmin Zhou <zhouzongmin@kylinos.cn>
> 
> When refresh_exported_devices() finds no devices, it's helpful to
> inform users about potential causes. This could be due to:
> 
> 1. The usbip driver module is not loaded.
> 2. No devices have been exported yet.
> 
> Add an informational message to guide users when ndevs == 0.
> 
> Message visibility by scenario:
> - usbipd (console mode): Show on console/serial, this allows instant
>    visibility for debugging.
> - usbipd -D (daemon mode): Message logged to syslog, can keep logs for
>    later traceability in production. Also can use "journalctl -f" to
>    trace on console.
> 
> Suggested-by: Shuah Khan <skhan@linuxfoundation.org>
> Signed-off-by: Zongmin Zhou <zhouzongmin@kylinos.cn>
> ---
> Changes in v3:
> - Just add an informational message when no devices are found.
> Changes in v2:
> - Use system calls directly instead of checking sysfs dir.
> 
>   tools/usb/usbip/libsrc/usbip_host_common.c | 7 +++++++
>   1 file changed, 7 insertions(+)
> 
> diff --git a/tools/usb/usbip/libsrc/usbip_host_common.c b/tools/usb/usbip/libsrc/usbip_host_common.c
> index ca78aa368476..cd92baee310c 100644
> --- a/tools/usb/usbip/libsrc/usbip_host_common.c
> +++ b/tools/usb/usbip/libsrc/usbip_host_common.c
> @@ -149,6 +149,13 @@ static int refresh_exported_devices(struct usbip_host_driver *hdriver)
>   		}
>   	}
>   
> +	if (hdriver->ndevs == 0) {
> +		if (!strcmp(hdriver->udev_subsystem, "usb"))
> +			info("Please check if %s driver is loaded or export devices.",USBIP_HOST_DRV_NAME);

Check coding guidelines and match the new code to the existing. Need a space between
the string and the next argument.


> +		else
> +			info("Please check if %s driver is loaded or export devices.",USBIP_DEVICE_DRV_NAME);

When will this be true? Isn't refresh_exported_devices() called from

Thinking about this more, since you have to differentiate between
host and device, it makes sense to make this change to

usbip_device_driver_open() and usbip_host_driver_open()
There is an err() message already in both of these routines.
that prints the right information.

You can check hdriver->ndevs == 0 and add an info that says
load appropriate modules or export devices. This way you
don't have to add logic to refresh_exported_devices() to figure
out which driver.

thanks,
-- Shuah
Re: [PATCH v3] usbip: tools: add hint when no exported devices are found
Posted by Zongmin Zhou 1 day, 22 hours ago
On 2026/4/1 08:27, Shuah Khan wrote:
> On 3/31/26 03:58, Zongmin Zhou wrote:
>> From: Zongmin Zhou <zhouzongmin@kylinos.cn>
>>
>> When refresh_exported_devices() finds no devices, it's helpful to
>> inform users about potential causes. This could be due to:
>>
>> 1. The usbip driver module is not loaded.
>> 2. No devices have been exported yet.
>>
>> Add an informational message to guide users when ndevs == 0.
>>
>> Message visibility by scenario:
>> - usbipd (console mode): Show on console/serial, this allows instant
>>    visibility for debugging.
>> - usbipd -D (daemon mode): Message logged to syslog, can keep logs for
>>    later traceability in production. Also can use "journalctl -f" to
>>    trace on console.
>>
>> Suggested-by: Shuah Khan <skhan@linuxfoundation.org>
>> Signed-off-by: Zongmin Zhou <zhouzongmin@kylinos.cn>
>> ---
>> Changes in v3:
>> - Just add an informational message when no devices are found.
>> Changes in v2:
>> - Use system calls directly instead of checking sysfs dir.
>>
>>   tools/usb/usbip/libsrc/usbip_host_common.c | 7 +++++++
>>   1 file changed, 7 insertions(+)
>>
>> diff --git a/tools/usb/usbip/libsrc/usbip_host_common.c 
>> b/tools/usb/usbip/libsrc/usbip_host_common.c
>> index ca78aa368476..cd92baee310c 100644
>> --- a/tools/usb/usbip/libsrc/usbip_host_common.c
>> +++ b/tools/usb/usbip/libsrc/usbip_host_common.c
>> @@ -149,6 +149,13 @@ static int refresh_exported_devices(struct 
>> usbip_host_driver *hdriver)
>>           }
>>       }
>>   +    if (hdriver->ndevs == 0) {
>> +        if (!strcmp(hdriver->udev_subsystem, "usb"))
>> +            info("Please check if %s driver is loaded or export 
>> devices.",USBIP_HOST_DRV_NAME);
>
> Check coding guidelines and match the new code to the existing. Need a 
> space between
> the string and the next argument.
>
>
>> +        else
>> +            info("Please check if %s driver is loaded or export 
>> devices.",USBIP_DEVICE_DRV_NAME);
>
> When will this be true? Isn't refresh_exported_devices() called from
>
> Thinking about this more, since you have to differentiate between
> host and device, it makes sense to make this change to
>
> usbip_device_driver_open() and usbip_host_driver_open()
> There is an err() message already in both of these routines.
> that prints the right information.
>
Shuah,

Regarding your comment about the existing err() message in these routines:

The existing err("please load *.ko") message only triggers when 
usbip_generic_driver_open()
returns a non-zero value. Since refresh_exported_devices() always returns 0
(even when ndevs == 0 and no devices are found), usbip_generic_driver_open()
only returns non-zero when udev_new() fails.

Therefore, when ndevs == 0, the existing err() message is never printed,
so it doesn't actually help users diagnose the "no devices found or 
driver not load" situation.

This is exactly why I previously suggested removing this misleading 
err() message.

Best regards,
Zongmin
> You can check hdriver->ndevs == 0 and add an info that says
> load appropriate modules or export devices. This way you
> don't have to add logic to refresh_exported_devices() to figure
> out which driver.
>
> thanks,
> -- Shuah

Re: [PATCH v3] usbip: tools: add hint when no exported devices are found
Posted by Shuah Khan 1 day, 9 hours ago
On 3/31/26 20:47, Zongmin Zhou wrote:
> 
> On 2026/4/1 08:27, Shuah Khan wrote:
>> On 3/31/26 03:58, Zongmin Zhou wrote:
>>> From: Zongmin Zhou <zhouzongmin@kylinos.cn>
>>>
>>> When refresh_exported_devices() finds no devices, it's helpful to
>>> inform users about potential causes. This could be due to:
>>>
>>> 1. The usbip driver module is not loaded.
>>> 2. No devices have been exported yet.
>>>
>>> Add an informational message to guide users when ndevs == 0.
>>>
>>> Message visibility by scenario:
>>> - usbipd (console mode): Show on console/serial, this allows instant
>>>    visibility for debugging.
>>> - usbipd -D (daemon mode): Message logged to syslog, can keep logs for
>>>    later traceability in production. Also can use "journalctl -f" to
>>>    trace on console.
>>>
>>> Suggested-by: Shuah Khan <skhan@linuxfoundation.org>
>>> Signed-off-by: Zongmin Zhou <zhouzongmin@kylinos.cn>
>>> ---
>>> Changes in v3:
>>> - Just add an informational message when no devices are found.
>>> Changes in v2:
>>> - Use system calls directly instead of checking sysfs dir.
>>>
>>>   tools/usb/usbip/libsrc/usbip_host_common.c | 7 +++++++
>>>   1 file changed, 7 insertions(+)
>>>
>>> diff --git a/tools/usb/usbip/libsrc/usbip_host_common.c b/tools/usb/usbip/libsrc/usbip_host_common.c
>>> index ca78aa368476..cd92baee310c 100644
>>> --- a/tools/usb/usbip/libsrc/usbip_host_common.c
>>> +++ b/tools/usb/usbip/libsrc/usbip_host_common.c
>>> @@ -149,6 +149,13 @@ static int refresh_exported_devices(struct usbip_host_driver *hdriver)
>>>           }
>>>       }
>>>   +    if (hdriver->ndevs == 0) {
>>> +        if (!strcmp(hdriver->udev_subsystem, "usb"))
>>> +            info("Please check if %s driver is loaded or export devices.",USBIP_HOST_DRV_NAME);
>>
>> Check coding guidelines and match the new code to the existing. Need a space between
>> the string and the next argument.
>>
>>
>>> +        else
>>> +            info("Please check if %s driver is loaded or export devices.",USBIP_DEVICE_DRV_NAME);
>>
>> When will this be true? Isn't refresh_exported_devices() called from
>>
>> Thinking about this more, since you have to differentiate between
>> host and device, it makes sense to make this change to
>>
>> usbip_device_driver_open() and usbip_host_driver_open()
>> There is an err() message already in both of these routines.
>> that prints the right information.
>>
> Shuah,
> 
> Regarding your comment about the existing err() message in these routines:
> 
> The existing err("please load *.ko") message only triggers when usbip_generic_driver_open()
> returns a non-zero value. Since refresh_exported_devices() always returns 0
> (even when ndevs == 0 and no devices are found), usbip_generic_driver_open()
> only returns non-zero when udev_new() fails.
> 
> Therefore, when ndevs == 0, the existing err() message is never printed,
> so it doesn't actually help users diagnose the "no devices found or driver not load" situation.

Correct. There is no need to remove this. What I am suggesting is these
messages from usbip_device_driver_open() and usbip_host_driver_open()

What I am suggesting changing usbip_device_driver_open() and
usbip_host_driver_open() like this:

if (ret || hdriver->ndevs == 0)
                 info("please load " USBIP_CORE_MOD_NAME ".ko and "
                     USBIP_DEVICE_DRV_NAME ".ko!");


This should solve the problem for you ...

I don't like the idea of adding string compares to refresh_exported_devices()

if (!strcmp(hdriver->udev_subsystem, "usb"))

to differentiate when you can simply leverage the existing code by adding
one more conditional and changing the err() to info()

thanks,
-- Shuah
[PATCH v4] usbip: tools: add hint when no exported devices are found
Posted by Zongmin Zhou 16 hours ago
From: Zongmin Zhou <zhouzongmin@kylinos.cn>

When refresh_exported_devices() finds no devices, it's helpful to
inform users about potential causes. This could be due to:

1. The usbip driver module is not loaded.
2. No devices have been exported yet.

Add an informational message to guide users when ndevs == 0.

Also update the condition in usbip_host_driver_open() and
usbip_device_driver_open() to check both ret and ndevs == 0,
and change err() to info().

Message visibility by scenario:
- usbipd (console mode): Show on console/serial, this allows instant
  visibility for debugging.
- usbipd -D (daemon mode): Message logged to syslog, can keep logs for
  later traceability in production. Also can use "journalctl -f" to
  trace on console.

Suggested-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Zongmin Zhou <zhouzongmin@kylinos.cn>
---
Changes in v4:
- Printing behavior adjusted as suggested.
Changes in v3:
- Just add an informational message when no devices are found.
Changes in v2:
- Use system calls directly instead of checking sysfs dir.

 tools/usb/usbip/libsrc/usbip_device_driver.c | 6 +++---
 tools/usb/usbip/libsrc/usbip_host_common.c   | 3 +++
 tools/usb/usbip/libsrc/usbip_host_driver.c   | 7 ++++---
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/tools/usb/usbip/libsrc/usbip_device_driver.c b/tools/usb/usbip/libsrc/usbip_device_driver.c
index 927a151fa9aa..1dfbb76ab26c 100644
--- a/tools/usb/usbip/libsrc/usbip_device_driver.c
+++ b/tools/usb/usbip/libsrc/usbip_device_driver.c
@@ -137,9 +137,9 @@ static int usbip_device_driver_open(struct usbip_host_driver *hdriver)
 	INIT_LIST_HEAD(&hdriver->edev_list);
 
 	ret = usbip_generic_driver_open(hdriver);
-	if (ret)
-		err("please load " USBIP_CORE_MOD_NAME ".ko and "
-		    USBIP_DEVICE_DRV_NAME ".ko!");
+	if (ret || hdriver->ndevs == 0)
+		info("please load " USBIP_CORE_MOD_NAME ".ko and "
+		     USBIP_DEVICE_DRV_NAME ".ko");
 
 	return ret;
 }
diff --git a/tools/usb/usbip/libsrc/usbip_host_common.c b/tools/usb/usbip/libsrc/usbip_host_common.c
index ca78aa368476..01599cb2fa7b 100644
--- a/tools/usb/usbip/libsrc/usbip_host_common.c
+++ b/tools/usb/usbip/libsrc/usbip_host_common.c
@@ -149,6 +149,9 @@ static int refresh_exported_devices(struct usbip_host_driver *hdriver)
 		}
 	}
 
+	if (hdriver->ndevs == 0)
+		info("Please load appropriate modules or export devices.");
+
 	return 0;
 }
 
diff --git a/tools/usb/usbip/libsrc/usbip_host_driver.c b/tools/usb/usbip/libsrc/usbip_host_driver.c
index 573e73ec36bd..bd8a6b84de0e 100644
--- a/tools/usb/usbip/libsrc/usbip_host_driver.c
+++ b/tools/usb/usbip/libsrc/usbip_host_driver.c
@@ -32,9 +32,10 @@ static int usbip_host_driver_open(struct usbip_host_driver *hdriver)
 	INIT_LIST_HEAD(&hdriver->edev_list);
 
 	ret = usbip_generic_driver_open(hdriver);
-	if (ret)
-		err("please load " USBIP_CORE_MOD_NAME ".ko and "
-		    USBIP_HOST_DRV_NAME ".ko!");
+	if (ret || hdriver->ndevs == 0)
+		info("please load " USBIP_CORE_MOD_NAME ".ko and "
+		     USBIP_HOST_DRV_NAME ".ko");
+
 	return ret;
 }
 
-- 
2.43.0