aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Clements <paul.clements@steeleye.com>2006-12-06 23:40:53 -0500
committerLinus Torvalds <torvalds@woody.osdl.org>2006-12-07 11:39:47 -0500
commit6b39bb6548d60b9a18826134b5ccd5c3cef85fe2 (patch)
tree8521d13c8518d4baa0ecfe2f1031524edb47d4d9
parent792908225064b1d841a8990b9d1d1cfc4e0e5bb2 (diff)
[PATCH] nbd: show nbd client pid in sysfs
Allow nbd to expose the nbd-client daemon's PID in /sys/block/nbd<x>/pid. This is helpful for tracking connection status of a device and for determining which nbd devices are currently in use. Signed-off-by: Paul Clements <paul.clements@steeleye.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--drivers/block/nbd.c16
-rw-r--r--include/linux/nbd.h1
2 files changed, 17 insertions, 0 deletions
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 9d1035e8d9d8..7bf2cfbd6285 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -355,14 +355,30 @@ harderror:
355 return NULL; 355 return NULL;
356} 356}
357 357
358static ssize_t pid_show(struct gendisk *disk, char *page)
359{
360 return sprintf(page, "%ld\n",
361 (long) ((struct nbd_device *)disk->private_data)->pid);
362}
363
364static struct disk_attribute pid_attr = {
365 .attr = { .name = "pid", .mode = S_IRUGO },
366 .show = pid_show,
367};
368
358static void nbd_do_it(struct nbd_device *lo) 369static void nbd_do_it(struct nbd_device *lo)
359{ 370{
360 struct request *req; 371 struct request *req;
361 372
362 BUG_ON(lo->magic != LO_MAGIC); 373 BUG_ON(lo->magic != LO_MAGIC);
363 374
375 lo->pid = current->pid;
376 sysfs_create_file(&lo->disk->kobj, &pid_attr.attr);
377
364 while ((req = nbd_read_stat(lo)) != NULL) 378 while ((req = nbd_read_stat(lo)) != NULL)
365 nbd_end_request(req); 379 nbd_end_request(req);
380
381 sysfs_remove_file(&lo->disk->kobj, &pid_attr.attr);
366 return; 382 return;
367} 383}
368 384
diff --git a/include/linux/nbd.h b/include/linux/nbd.h
index d6b6dc09ad97..0f3e69302540 100644
--- a/include/linux/nbd.h
+++ b/include/linux/nbd.h
@@ -64,6 +64,7 @@ struct nbd_device {
64 struct gendisk *disk; 64 struct gendisk *disk;
65 int blksize; 65 int blksize;
66 u64 bytesize; 66 u64 bytesize;
67 pid_t pid; /* pid of nbd-client, if attached */
67}; 68};
68 69
69#endif 70#endif