public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fs/partitions/check: add sysfs error handling
@ 2006-10-04 12:19 Jeff Garzik
  2006-10-04 12:26 ` Al Viro
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff Garzik @ 2006-10-04 12:19 UTC (permalink / raw)
  To: Al Viro, Andrew Morton, LKML


Handle errors thrown in disk_sysfs_symlinks(), and propagate back
to caller.

The callers and associated functions don't do a real good job
of handling kobject errors anyway (add_partition, register_disk,
rescan_partitions), so this should do until something better comes
along.

Signed-off-by: Jeff Garzik <jeff@garzik.org>

---

 fs/partitions/check.c |   50 ++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 42 insertions(+), 8 deletions(-)

diff --git a/fs/partitions/check.c b/fs/partitions/check.c
index 51c6a74..6fb4b61 100644
--- a/fs/partitions/check.c
+++ b/fs/partitions/check.c
@@ -376,18 +376,48 @@ static char *make_block_name(struct gend
 	return name;
 }
 
-static void disk_sysfs_symlinks(struct gendisk *disk)
+static int disk_sysfs_symlinks(struct gendisk *disk)
 {
 	struct device *target = get_device(disk->driverfs_dev);
+	int err;
+	char *disk_name = NULL;
+
 	if (target) {
-		char *disk_name = make_block_name(disk);
-		sysfs_create_link(&disk->kobj,&target->kobj,"device");
-		if (disk_name) {
-			sysfs_create_link(&target->kobj,&disk->kobj,disk_name);
-			kfree(disk_name);
+		disk_name = make_block_name(disk);
+		if (!disk_name) {
+			err = -ENOMEM;
+			goto err_out;
 		}
+
+		err = sysfs_create_link(&disk->kobj, &target->kobj, "device");
+		if (err)
+			goto err_out_disk_name;
+
+		err = sysfs_create_link(&target->kobj, &disk->kobj, disk_name);
+		if (err)
+			goto err_out_dev_link;
 	}
-	sysfs_create_link(&disk->kobj, &block_subsys.kset.kobj, "subsystem");
+
+	err = sysfs_create_link(&disk->kobj, &block_subsys.kset.kobj,
+				"subsystem");
+	if (err)
+		goto err_out_disk_name_lnk;
+
+	kfree(disk_name);
+
+	return 0;
+
+err_out_disk_name_lnk:
+	if (target) {
+		sysfs_remove_link(&target->kobj, disk_name);
+err_out_dev_link:
+		sysfs_remove_link(&disk->kobj, "device");
+err_out_disk_name:
+		kfree(disk_name);
+err_out:
+		put_device(target);
+	}
+	return err;
 }
 
 /* Not exported, helper to add_disk(). */
@@ -406,7 +436,11 @@ void register_disk(struct gendisk *disk)
 		*s = '!';
 	if ((err = kobject_add(&disk->kobj)))
 		return;
-	disk_sysfs_symlinks(disk);
+	err = disk_sysfs_symlinks(disk);
+	if (err) {
+		kobject_del(&disk->kobj);
+		return;
+	}
  	disk_sysfs_add_subdirs(disk);
 
 	/* No minors to use for partitions */

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] fs/partitions/check: add sysfs error handling
  2006-10-04 12:19 [PATCH] fs/partitions/check: add sysfs error handling Jeff Garzik
@ 2006-10-04 12:26 ` Al Viro
  2006-10-04 13:10   ` Jeff Garzik
  0 siblings, 1 reply; 3+ messages in thread
From: Al Viro @ 2006-10-04 12:26 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: Andrew Morton, LKML

On Wed, Oct 04, 2006 at 08:19:00AM -0400, Jeff Garzik wrote:
> 
> Handle errors thrown in disk_sysfs_symlinks(), and propagate back
> to caller.
> 
> The callers and associated functions don't do a real good job
> of handling kobject errors anyway (add_partition, register_disk,
> rescan_partitions), so this should do until something better comes
> along.

I'm not sure that failure to create these symlinks should be fatal,
to be honest...

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] fs/partitions/check: add sysfs error handling
  2006-10-04 12:26 ` Al Viro
@ 2006-10-04 13:10   ` Jeff Garzik
  0 siblings, 0 replies; 3+ messages in thread
From: Jeff Garzik @ 2006-10-04 13:10 UTC (permalink / raw)
  To: Al Viro; +Cc: Andrew Morton, LKML

Al Viro wrote:
> On Wed, Oct 04, 2006 at 08:19:00AM -0400, Jeff Garzik wrote:
>> Handle errors thrown in disk_sysfs_symlinks(), and propagate back
>> to caller.
>>
>> The callers and associated functions don't do a real good job
>> of handling kobject errors anyway (add_partition, register_disk,
>> rescan_partitions), so this should do until something better comes
>> along.
> 
> I'm not sure that failure to create these symlinks should be fatal,
> to be honest...

Fair enough, though FWIW the failure is almost always -EFAULT or 
-ENOMEM, i.e. -ESYSTEMINTROUBLE...

	Jeff




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-10-04 13:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-10-04 12:19 [PATCH] fs/partitions/check: add sysfs error handling Jeff Garzik
2006-10-04 12:26 ` Al Viro
2006-10-04 13:10   ` Jeff Garzik

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox