diff options
author | Paul Clements <paul.clements@steeleye.com> | 2006-12-06 23:40:53 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.osdl.org> | 2006-12-07 11:39:47 -0500 |
commit | 6b39bb6548d60b9a18826134b5ccd5c3cef85fe2 (patch) | |
tree | 8521d13c8518d4baa0ecfe2f1031524edb47d4d9 /drivers | |
parent | 792908225064b1d841a8990b9d1d1cfc4e0e5bb2 (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>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/block/nbd.c | 16 |
1 files changed, 16 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 | ||
358 | static 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 | |||
364 | static struct disk_attribute pid_attr = { | ||
365 | .attr = { .name = "pid", .mode = S_IRUGO }, | ||
366 | .show = pid_show, | ||
367 | }; | ||
368 | |||
358 | static void nbd_do_it(struct nbd_device *lo) | 369 | static 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 | ||