summaryrefslogtreecommitdiff
path: root/namedev.c
diff options
context:
space:
mode:
authorkay.sievers@vrfy.org <kay.sievers@vrfy.org>2004-11-06 14:28:01 +0100
committerGreg KH <gregkh@suse.de>2005-04-26 22:16:40 -0700
commit2b41e68a08548ce44b4d145900dab2bb04cd34f7 (patch)
treef2e96c9f150775e3673891d38a5af23d4246c826 /namedev.c
parent482b0ecd8fcc2651c003c6f1ae9a2d3301ecf34a (diff)
[PATCH] replace tdb database by simple lockless file database
This makes the udev operation completely lockless by storing a file for every node in /dev/.udevdb/* This solved the problem with deadlocking concurrent udev processes waiting for each other to release the file lock under heavy load.
Diffstat (limited to 'namedev.c')
-rw-r--r--namedev.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/namedev.c b/namedev.c
index f3fb3ff7ed..d63e36e18a 100644
--- a/namedev.c
+++ b/namedev.c
@@ -184,29 +184,29 @@ static int get_format_len(char **str)
* @param name Name to check for
* @return 0 if <name> didn't exist and N otherwise.
*/
-static unsigned int find_free_number (struct udevice *udev, char *name)
+static int find_free_number(struct udevice *udev, const char *name)
{
- char temp[NAME_SIZE];
- char path[NAME_SIZE];
- struct udevice dev;
- int result;
+ char filename[NAME_SIZE];
+ int num = 0;
+ struct udevice db_udev;
- /* have to sweep the database for each lookup */
- result = 0;
- strncpy(temp, name, sizeof (temp));
+ strfieldcpy(filename, name);
while (1) {
- if (udevdb_get_dev_byname(temp, path, &dev) != 0)
- goto found;
- /* symlink might be stale if $(udevroot) isn't cleaned; check
- * on major/minor to see if it's the same device
- */
- if (dev.major == udev->major && dev.minor == udev->minor)
- goto found;
- snprintf (temp, sizeof(temp), "%s%d", name, ++result);
- }
+ dbg("look for existing node '%s'", filename);
+ memset(&db_udev, 0x00, sizeof(struct udevice));
+ if (udevdb_get_dev_byname(&db_udev, filename) != 0) {
+ dbg("free num=%d", num);
+ return num;
+ }
-found:
- return result;
+ num++;
+ if (num > 1000) {
+ info("find_free_number gone crazy (num=%d), aborted", num);
+ return -1;
+ }
+ snprintf(filename, NAME_SIZE-1, "%s%d", name, num);
+ filename[NAME_SIZE-1] = '\0';
+ }
}
static void apply_format(struct udevice *udev, char *string, size_t maxsize,
@@ -329,7 +329,7 @@ static void apply_format(struct udevice *udev, char *string, size_t maxsize,
case 'e':
next_free_number = find_free_number(udev, string);
if (next_free_number > 0) {
- snprintf(temp2, sizeof(temp2), "%d", next_free_number);
+ sprintf(temp2, "%d", next_free_number);
strfieldcatmax(string, temp2, maxsize);
}
break;