Skip to contentSkip to conversation

blktrace: avoid device duplication

PATCH In review Edward Shishkin 2 participants 2 messages Dec 15, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 blktrace: avoid device duplication

Fixup for bz 501457.

Problem:
If the device list file contains the same device as supplied on the command line, blktrace stops immediately and further I/O tracing is impossible.

Bug: device duplication in the devpaths ends with programm termination (BLKTRACESETUP ioctl returns error) while resources (open files in debugfs) are not released.

Solution:
Make sure devices are not duplicated in devpaths pool.

---
 blktrace.c |    9 +++++++++
 1 file changed, 9 insertions(+)
blktrace.c +9 -0
@@ -1200,8 +1200,17 @@ static int add_devpath(char *path)
 {
 	int fd;
 	struct devpath *dpp;
+	struct list_head *p;
 
 	/*
+	 * Verify device is not duplicated
+	 */
+	__list_for_each(p, &devpaths) {
+	       struct devpath *tmp = list_entry(p, struct devpath, head);
+	       if (!strcmp(tmp->path, path))
+		        return 0;
+	}
+	/*
 	 * Verify device is valid before going too far
 	 */
 	fd = my_open(path, O_RDONLY | O_NONBLOCK);
#1 lore raw
Quoted 2 lines · Edward Shishkin

Fixup for bz 501457.

Just to be clear, these are Red Hat bugzilla numbers, i.e.

https://bugzilla.redhat.com/show_bug.cgi?idP1457

Thanks,
-Eric

Quoted 39 lines

Problem:
If the device list file contains the same device as supplied on the command line, blktrace stops immediately and further I/O tracing is impossible.

Bug: device duplication in the devpaths ends with programm termination (BLKTRACESETUP ioctl returns error) while resources (open files in debugfs) are not released.

Solution:
Make sure devices are not duplicated in devpaths pool.

---
 blktrace.c |    9 +++++++++
 1 file changed, 9 insertions(+)
blktrace.c +9 -0
@@ -1200,8 +1200,17 @@ static int add_devpath(char *path)
 {
 	int fd;
 	struct devpath *dpp;
+	struct list_head *p;
 
 	/*
+	 * Verify device is not duplicated
+	 */
+	__list_for_each(p, &devpaths) {
+	       struct devpath *tmp = list_entry(p, struct devpath, head);
+	       if (!strcmp(tmp->path, path))
+		        return 0;
+	}
+	/*
 	 * Verify device is valid before going too far
 	 */
 	fd = my_open(path, O_RDONLY | O_NONBLOCK);