Skip to contentSkip to conversation

udev: provide temporary device nodes for callouts

DISCUSSION Kay Sievers 3 participants 10 messages Feb 10, 2005

lore
Share & tools
lore
#0 lore raw

I've added some code to udev to solve the problem of accessing devices from a callout while no device node is created at that time, cause obviously the callout runs to return the name for the node to be created.

Some programs need to access the device to read labels or serial numbers from, but can't know where to create a temporary node, cause udev_root may be at an unknown location or /tmp is read-only.

%N - create a temporary node and substitute its name
It will be created in udev_root as .tmp-<major>-<minor> The node is removed after the namedev call.

%p - substitute the DEVPATH of the device
For scsi_id to be called from the command line.

%P - substitute the name of the parent device
The node name of the parent device is queried from the udevdb. This makes it easy to name partitions after the main device, especially if the main device gets its name from a callout or to get the disklabel of the main device to name a partition.

%r - substitute udev_root
Needed to pass the absolute name of the parent device node to a callout

The following examples of disklabel reading apply with different commandline parameters also to scsi_id, that reads the serial number from the main device.

Name partitions after disklabel of the parent:
SUBSYSTEM="block", KERNEL="*[1-9]", PROGRAM="/sbin/udev_volume_id -l %r/%P" NAME="%c-part%n"

Name main device after disklabel and let partitions follow the name of the main device. udevd serializes the events, so that we can be sure, that the node of the main device is created before the partition event tries to access it:
SUBSYSTEM="block", KERNEL="*[a-z]", PROGRAM="/sbin/udev_volume_id -l %N, NAME="%c" SUBSYSTEM="block", KERNEL="*[1-9]", NAME="%P-part%n"

Name partitions after filestem label:
SUBSYSTEM="block", KERNEL="*[1-9]", PROGRAM="/sbin/udev_volume_id -l %N"

udev_volume_id does not longer create any temporary device node or searches the parent device by itself. It expects the name of the node as illustrated in the examples.

Thanks,
Kay

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_ide95&alloc_id396&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#1 lore raw
Quoted 3 lines · Kay Sievers

%N - create a temporary node and substitute its name
It will be created in udev_root as .tmp-<major>-<minor> The node is removed after the namedev call.

Hi Kay -

I tested with scsi_id, and found no S_IF* was being set for the mknod mode.

The following patch fixed the problem.

=== namedev.c 1.176 vs edited ==--- 1.176/namedev.c Wed Feb 9 16:03:54 2005
+++ edited/namedev.c Thu Feb 10 09:07:55 2005
@@ -184,6 +184,7 @@
struct sysfs_attribute *tmpattr; unsigned int next_free_number; struct sysfs_class_device *class_dev_parent;
+ mode_t mode;

pos = string;
while (1) {
@@ -316,8 +317,11 @@
case 'N':
if (udev->tmp_node[0] = '\0') {
dbg("create temporary device node for callout");
+ mode = get_mode_type(udev);
+ if (!mode)
+ break;
snprintf(udev->tmp_node, NAME_SIZE-1, "%s/.tmp-%u-%u", udev_root, udev->major, udev->minor);
- udev_make_node(udev, udev->tmp_node, udev->major, udev->minor, 0600, 0, 0);
+ udev_make_node(udev, udev->tmp_node, udev->major, udev->minor, mode | 0600, 0, 0);
}
strfieldcatmax(string, udev->tmp_node, maxsize);
dbg("substitute temporary device node name '%s'", udev->tmp_node);
=== udev_add.c 1.91 vs edited ==--- 1.91/udev_add.c Tue Feb 8 15:43:18 2005
+++ edited/udev_add.c Thu Feb 10 09:13:31 2005
@@ -126,26 +126,16 @@
int tail;
char *pos;
int len;
+ mode_t mode;
int i;

snprintf(filename, NAME_SIZE, "%s/%s", udev_root, udev->name); filename[NAME_SIZE-1] = '\0';

- switch (udev->type) {
- case 'b':
- udev->mode |= S_IFBLK;
- break;
- case 'c':
- case 'u':
- udev->mode |= S_IFCHR;
- break;
- case 'p':
- udev->mode |= S_IFIFO;
- break;
- default:
- dbg("unknown node type %c\n", udev->type);
+ mode = get_mode_type(udev);
+ if (!mode)
return -EINVAL;
- }
+ udev->mode |= mode;

/* create parent directories if needed */
if (strrchr(udev->name, '/'))
=== udev_utils.c 1.29 vs edited ==--- 1.29/udev_utils.c Wed Feb 9 12:51:41 2005
+++ edited/udev_utils.c Thu Feb 10 09:09:33 2005
@@ -314,3 +314,19 @@
closedir(dir);
return 0;
}
+
+mode_t get_mode_type (struct udevice *udev)
+{
+ switch (udev->type) {
+ case 'b':
+ return S_IFBLK;
+ case 'c':
+ case 'u':
+ return S_IFCHR;
+ case 'p':
+ return S_IFIFO;
+ default:
+ dbg("unknown node type %c\n", udev->type);
+ return 0;
+ }
+}
=== udev_utils.h 1.22 vs edited ==--- 1.22/udev_utils.h Tue Feb 8 11:37:31 2005
+++ edited/udev_utils.h Thu Feb 10 09:04:52 2005
@@ -88,5 +88,6 @@
typedef int (*file_fnct_t)(const char *filename, void *data); extern int call_foreach_file(file_fnct_t fnct, const char *dirname,
const char *suffix, void *data);
+extern mode_t get_mode_type (struct udevice *udev);

#endif

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_ide95&alloc_id396&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#2 lore raw
In reply to Kay Sievers
Quoted 9 lines · Patrick Mansfield
Quoted 3 lines · Kay Sievers

%N - create a temporary node and substitute its name
It will be created in udev_root as .tmp-<major>-<minor> The node is removed after the namedev call.

Hi Kay -

I tested with scsi_id, and found no S_IF* was being set for the mknod mode.

Yeah, sorry. It's already fixed in my tree.

Kay

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_ide95&alloc_id396&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#3 lore raw
In reply to Kay Sievers
Quoted 6 lines · Kay Sievers
Quoted 5 lines · Patrick Mansfield
Quoted 3 lines · Kay Sievers

%N - create a temporary node and substitute its name
It will be created in udev_root as .tmp-<major>-<minor> The node is removed after the namedev call.

Quoted 6 lines
Quoted 4 lines

Hi Kay -

I tested with scsi_id, and found no S_IF* was being set for the mknod mode.

Yeah, sorry. It's already fixed in my tree.

Okay ... I checked greg's tree.

Why was the test passing?

-- Patrick Mansfield

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_ide95&alloc_id396&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#4 lore raw
In reply to Kay Sievers
Quoted 9 lines · Patrick Mansfield
Quoted 8 lines · Kay Sievers
Quoted 7 lines · Patrick Mansfield
Quoted 3 lines · Kay Sievers

%N - create a temporary node and substitute its name
It will be created in udev_root as .tmp-<major>-<minor> The node is removed after the namedev call.

Hi Kay -

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

I tested with scsi_id, and found no S_IF* was being set for the mknod mode.

Yeah, sorry. It's already fixed in my tree.

Okay ... I checked greg's tree.

Why was the test passing?

The test tested that it was _no_ block device. :)

Kay

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_ide95&alloc_id396&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#5 lore raw
In reply to Kay Sievers
Quoted 7 lines · Patrick Mansfield
Quoted 6 lines · Kay Sievers
Quoted 5 lines · Patrick Mansfield
Quoted 3 lines · Kay Sievers

%N - create a temporary node and substitute its name
It will be created in udev_root as .tmp-<major>-<minor> The node is removed after the namedev call.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Hi Kay -

I tested with scsi_id, and found no S_IF* was being set for the mknod mode.

Yeah, sorry. It's already fixed in my tree.

Okay ... I checked greg's tree.

Kay's fix is in my tree now too, I just pushed it out.

Looks like it's time for another release...

thanks,

greg k-h

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_ide95&alloc_id396&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#6 lore raw
In reply to Kay Sievers
Quoted 3 lines · Patrick Mansfield

Why was the test passing?

I was confused by the test rule that was *not* supposed to match, i.e. this is easier to read:

=== test/udev-test.pl 1.80 vs edited ==--- 1.80/test/udev-test.pl Thu Feb 10 02:46:49 2005
+++ edited/test/udev-test.pl Thu Feb 10 10:03:59 2005
@@ -1066,9 +1066,9 @@
desc => "temporary node creation test",
subsys => "block",
devpath => "/block/sda",
- exp_name => "sda",
+ exp_name => "node",
conf => <<EOF
-BUS="scsi", KERNEL="sda", PROGRAM="/usr/bin/test ! -b %N" NAME="%N" +BUS="scsi", KERNEL="sda", PROGRAM="/usr/bin/test -b %N" NAME="node"
EOF
},
{

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_ide95&alloc_id396&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#7 lore raw
In reply to Kay Sievers
Quoted 12 lines · Patrick Mansfield
Quoted 3 lines · Patrick Mansfield

Why was the test passing?

I was confused by the test rule that was *not* supposed to match, i.e. this is easier to read:

=== test/udev-test.pl 1.80 vs edited ==> --- 1.80/test/udev-test.pl Thu Feb 10 02:46:49 2005
+++ edited/test/udev-test.pl Thu Feb 10 10:03:59 2005

(quoted diff) +0 -0
@@ -1066,9 +1066,9 @@
 		desc		=> "temporary node creation test",

Review line 1074

Quoted 10 lines
(quoted diff) +2 -2
 		subsys		=> "block",
 		devpath		=> "/block/sda",
-		exp_name	=> "sda",
+		exp_name	=> "node",
 		conf		=> <<EOF
-BUS="scsi", KERNEL="sda", PROGRAM="/usr/bin/test ! -b %N" NAME="%N"
+BUS="scsi", KERNEL="sda", PROGRAM="/usr/bin/test -b %N" NAME="node"
 EOF
 	},
 	{

Yes, that's much better.

Thanks,
Kay

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_ide95&alloc_id396&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#8 lore raw
In reply to Kay Sievers
Quoted 3 lines · Greg KH

Kay's fix is in my tree now too, I just pushed it out.

Looks like it's time for another release...

Can you wait a day or so?

I still have to fix scsi_id to set its hotplug_mode, probably if DEVPATH and/or UDEV_LOG are set, so it will log errors via strlog when run with "-d" option when invoked via udev.

-- Patrick Mansfield

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_ide95&alloc_id396&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#9 lore raw
In reply to Kay Sievers
Quoted 11 lines · Patrick Mansfield
Quoted 3 lines · Greg KH

Kay's fix is in my tree now too, I just pushed it out.

Looks like it's time for another release...

Can you wait a day or so?

I still have to fix scsi_id to set its hotplug_mode, probably if DEVPATH and/or UDEV_LOG are set, so it will log errors via strlog when run with "-d" option when invoked via udev.

Sure, let me know when you are ready. There's already a 052 release out there that I forgot to announce...

thanks,

greg k-h

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_ide95&alloc_id396&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel