diff options
author | Joel Becker <joel.becker@oracle.com> | 2008-07-17 18:21:29 -0400 |
---|---|---|
committer | Joel Becker <joel.becker@oracle.com> | 2008-07-17 18:21:29 -0400 |
commit | a6795e9ebb420d87af43789174689af0d66d1d35 (patch) | |
tree | fb2a86ad010015fdd311f3b7f6ef30f60c14b8f7 /fs | |
parent | f89ab8619e5320cc9c2576f5f8dcbaf6c0ba3950 (diff) |
configfs: Allow ->make_item() and ->make_group() to return detailed errors.
The configfs operations ->make_item() and ->make_group() currently
return a new item/group. A return of NULL signifies an error. Because
of this, -ENOMEM is the only return code bubbled up the stack.
Multiple folks have requested the ability to return specific error codes
when these operations fail. This patch adds that ability by changing the
->make_item/group() ops to return ERR_PTR() values. These errors are
bubbled up appropriately. NULL returns are changed to -ENOMEM for
compatibility.
Also updated are the in-kernel users of configfs.
This is a rework of reverted commit 11c3b79218390a139f2d474ee1e983a672d5839a.
Signed-off-by: Joel Becker <joel.becker@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/configfs/dir.c | 25 | ||||
-rw-r--r-- | fs/dlm/config.c | 8 | ||||
-rw-r--r-- | fs/ocfs2/cluster/heartbeat.c | 10 | ||||
-rw-r--r-- | fs/ocfs2/cluster/nodemanager.c | 16 |
4 files changed, 26 insertions, 33 deletions
diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c index 614e382a6049..179589be063a 100644 --- a/fs/configfs/dir.c +++ b/fs/configfs/dir.c | |||
@@ -1027,9 +1027,10 @@ EXPORT_SYMBOL(configfs_undepend_item); | |||
1027 | 1027 | ||
1028 | static int configfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) | 1028 | static int configfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) |
1029 | { | 1029 | { |
1030 | int ret, module_got = 0; | 1030 | int ret = 0; |
1031 | struct config_group *group; | 1031 | int module_got = 0; |
1032 | struct config_item *item; | 1032 | struct config_group *group = NULL; |
1033 | struct config_item *item = NULL; | ||
1033 | struct config_item *parent_item; | 1034 | struct config_item *parent_item; |
1034 | struct configfs_subsystem *subsys; | 1035 | struct configfs_subsystem *subsys; |
1035 | struct configfs_dirent *sd; | 1036 | struct configfs_dirent *sd; |
@@ -1070,28 +1071,32 @@ static int configfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) | |||
1070 | snprintf(name, dentry->d_name.len + 1, "%s", dentry->d_name.name); | 1071 | snprintf(name, dentry->d_name.len + 1, "%s", dentry->d_name.name); |
1071 | 1072 | ||
1072 | mutex_lock(&subsys->su_mutex); | 1073 | mutex_lock(&subsys->su_mutex); |
1073 | group = NULL; | ||
1074 | item = NULL; | ||
1075 | if (type->ct_group_ops->make_group) { | 1074 | if (type->ct_group_ops->make_group) { |
1076 | group = type->ct_group_ops->make_group(to_config_group(parent_item), name); | 1075 | group = type->ct_group_ops->make_group(to_config_group(parent_item), name); |
1077 | if (group) { | 1076 | if (!group) |
1077 | group = ERR_PTR(-ENOMEM); | ||
1078 | if (!IS_ERR(group)) { | ||
1078 | link_group(to_config_group(parent_item), group); | 1079 | link_group(to_config_group(parent_item), group); |
1079 | item = &group->cg_item; | 1080 | item = &group->cg_item; |
1080 | } | 1081 | } else |
1082 | ret = PTR_ERR(group); | ||
1081 | } else { | 1083 | } else { |
1082 | item = type->ct_group_ops->make_item(to_config_group(parent_item), name); | 1084 | item = type->ct_group_ops->make_item(to_config_group(parent_item), name); |
1083 | if (item) | 1085 | if (!item) |
1086 | item = ERR_PTR(-ENOMEM); | ||
1087 | if (!IS_ERR(item)) | ||
1084 | link_obj(parent_item, item); | 1088 | link_obj(parent_item, item); |
1089 | else | ||
1090 | ret = PTR_ERR(item); | ||
1085 | } | 1091 | } |
1086 | mutex_unlock(&subsys->su_mutex); | 1092 | mutex_unlock(&subsys->su_mutex); |
1087 | 1093 | ||
1088 | kfree(name); | 1094 | kfree(name); |
1089 | if (!item) { | 1095 | if (ret) { |
1090 | /* | 1096 | /* |
1091 | * If item == NULL, then link_obj() was never called. | 1097 | * If item == NULL, then link_obj() was never called. |
1092 | * There are no extra references to clean up. | 1098 | * There are no extra references to clean up. |
1093 | */ | 1099 | */ |
1094 | ret = -ENOMEM; | ||
1095 | goto out_put; | 1100 | goto out_put; |
1096 | } | 1101 | } |
1097 | 1102 | ||
diff --git a/fs/dlm/config.c b/fs/dlm/config.c index eac23bd288b2..c4e7d721bd8d 100644 --- a/fs/dlm/config.c +++ b/fs/dlm/config.c | |||
@@ -438,7 +438,7 @@ static struct config_group *make_cluster(struct config_group *g, | |||
438 | kfree(gps); | 438 | kfree(gps); |
439 | kfree(sps); | 439 | kfree(sps); |
440 | kfree(cms); | 440 | kfree(cms); |
441 | return NULL; | 441 | return ERR_PTR(-ENOMEM); |
442 | } | 442 | } |
443 | 443 | ||
444 | static void drop_cluster(struct config_group *g, struct config_item *i) | 444 | static void drop_cluster(struct config_group *g, struct config_item *i) |
@@ -495,7 +495,7 @@ static struct config_group *make_space(struct config_group *g, const char *name) | |||
495 | kfree(sp); | 495 | kfree(sp); |
496 | kfree(gps); | 496 | kfree(gps); |
497 | kfree(nds); | 497 | kfree(nds); |
498 | return NULL; | 498 | return ERR_PTR(-ENOMEM); |
499 | } | 499 | } |
500 | 500 | ||
501 | static void drop_space(struct config_group *g, struct config_item *i) | 501 | static void drop_space(struct config_group *g, struct config_item *i) |
@@ -528,7 +528,7 @@ static struct config_item *make_comm(struct config_group *g, const char *name) | |||
528 | 528 | ||
529 | cm = kzalloc(sizeof(struct comm), GFP_KERNEL); | 529 | cm = kzalloc(sizeof(struct comm), GFP_KERNEL); |
530 | if (!cm) | 530 | if (!cm) |
531 | return NULL; | 531 | return ERR_PTR(-ENOMEM); |
532 | 532 | ||
533 | config_item_init_type_name(&cm->item, name, &comm_type); | 533 | config_item_init_type_name(&cm->item, name, &comm_type); |
534 | cm->nodeid = -1; | 534 | cm->nodeid = -1; |
@@ -561,7 +561,7 @@ static struct config_item *make_node(struct config_group *g, const char *name) | |||
561 | 561 | ||
562 | nd = kzalloc(sizeof(struct node), GFP_KERNEL); | 562 | nd = kzalloc(sizeof(struct node), GFP_KERNEL); |
563 | if (!nd) | 563 | if (!nd) |
564 | return NULL; | 564 | return ERR_PTR(-ENOMEM); |
565 | 565 | ||
566 | config_item_init_type_name(&nd->item, name, &node_type); | 566 | config_item_init_type_name(&nd->item, name, &node_type); |
567 | nd->nodeid = -1; | 567 | nd->nodeid = -1; |
diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c index f02ccb34604d..7dce1612553e 100644 --- a/fs/ocfs2/cluster/heartbeat.c +++ b/fs/ocfs2/cluster/heartbeat.c | |||
@@ -1493,24 +1493,18 @@ static struct config_item *o2hb_heartbeat_group_make_item(struct config_group *g | |||
1493 | const char *name) | 1493 | const char *name) |
1494 | { | 1494 | { |
1495 | struct o2hb_region *reg = NULL; | 1495 | struct o2hb_region *reg = NULL; |
1496 | struct config_item *ret = NULL; | ||
1497 | 1496 | ||
1498 | reg = kzalloc(sizeof(struct o2hb_region), GFP_KERNEL); | 1497 | reg = kzalloc(sizeof(struct o2hb_region), GFP_KERNEL); |
1499 | if (reg == NULL) | 1498 | if (reg == NULL) |
1500 | goto out; /* ENOMEM */ | 1499 | return ERR_PTR(-ENOMEM); |
1501 | 1500 | ||
1502 | config_item_init_type_name(®->hr_item, name, &o2hb_region_type); | 1501 | config_item_init_type_name(®->hr_item, name, &o2hb_region_type); |
1503 | 1502 | ||
1504 | ret = ®->hr_item; | ||
1505 | |||
1506 | spin_lock(&o2hb_live_lock); | 1503 | spin_lock(&o2hb_live_lock); |
1507 | list_add_tail(®->hr_all_item, &o2hb_all_regions); | 1504 | list_add_tail(®->hr_all_item, &o2hb_all_regions); |
1508 | spin_unlock(&o2hb_live_lock); | 1505 | spin_unlock(&o2hb_live_lock); |
1509 | out: | ||
1510 | if (ret == NULL) | ||
1511 | kfree(reg); | ||
1512 | 1506 | ||
1513 | return ret; | 1507 | return ®->hr_item; |
1514 | } | 1508 | } |
1515 | 1509 | ||
1516 | static void o2hb_heartbeat_group_drop_item(struct config_group *group, | 1510 | static void o2hb_heartbeat_group_drop_item(struct config_group *group, |
diff --git a/fs/ocfs2/cluster/nodemanager.c b/fs/ocfs2/cluster/nodemanager.c index cfdb08b484ed..816a3f61330c 100644 --- a/fs/ocfs2/cluster/nodemanager.c +++ b/fs/ocfs2/cluster/nodemanager.c | |||
@@ -648,26 +648,19 @@ static struct config_item *o2nm_node_group_make_item(struct config_group *group, | |||
648 | const char *name) | 648 | const char *name) |
649 | { | 649 | { |
650 | struct o2nm_node *node = NULL; | 650 | struct o2nm_node *node = NULL; |
651 | struct config_item *ret = NULL; | ||
652 | 651 | ||
653 | if (strlen(name) > O2NM_MAX_NAME_LEN) | 652 | if (strlen(name) > O2NM_MAX_NAME_LEN) |
654 | goto out; /* ENAMETOOLONG */ | 653 | return ERR_PTR(-ENAMETOOLONG); |
655 | 654 | ||
656 | node = kzalloc(sizeof(struct o2nm_node), GFP_KERNEL); | 655 | node = kzalloc(sizeof(struct o2nm_node), GFP_KERNEL); |
657 | if (node == NULL) | 656 | if (node == NULL) |
658 | goto out; /* ENOMEM */ | 657 | return ERR_PTR(-ENOMEM); |
659 | 658 | ||
660 | strcpy(node->nd_name, name); /* use item.ci_namebuf instead? */ | 659 | strcpy(node->nd_name, name); /* use item.ci_namebuf instead? */ |
661 | config_item_init_type_name(&node->nd_item, name, &o2nm_node_type); | 660 | config_item_init_type_name(&node->nd_item, name, &o2nm_node_type); |
662 | spin_lock_init(&node->nd_lock); | 661 | spin_lock_init(&node->nd_lock); |
663 | 662 | ||
664 | ret = &node->nd_item; | 663 | return &node->nd_item; |
665 | |||
666 | out: | ||
667 | if (ret == NULL) | ||
668 | kfree(node); | ||
669 | |||
670 | return ret; | ||
671 | } | 664 | } |
672 | 665 | ||
673 | static void o2nm_node_group_drop_item(struct config_group *group, | 666 | static void o2nm_node_group_drop_item(struct config_group *group, |
@@ -762,7 +755,7 @@ static struct config_group *o2nm_cluster_group_make_group(struct config_group *g | |||
762 | /* this runs under the parent dir's i_mutex; there can be only | 755 | /* this runs under the parent dir's i_mutex; there can be only |
763 | * one caller in here at a time */ | 756 | * one caller in here at a time */ |
764 | if (o2nm_single_cluster) | 757 | if (o2nm_single_cluster) |
765 | goto out; /* ENOSPC */ | 758 | return ERR_PTR(-ENOSPC); |
766 | 759 | ||
767 | cluster = kzalloc(sizeof(struct o2nm_cluster), GFP_KERNEL); | 760 | cluster = kzalloc(sizeof(struct o2nm_cluster), GFP_KERNEL); |
768 | ns = kzalloc(sizeof(struct o2nm_node_group), GFP_KERNEL); | 761 | ns = kzalloc(sizeof(struct o2nm_node_group), GFP_KERNEL); |
@@ -795,6 +788,7 @@ out: | |||
795 | kfree(ns); | 788 | kfree(ns); |
796 | o2hb_free_hb_set(o2hb_group); | 789 | o2hb_free_hb_set(o2hb_group); |
797 | kfree(defs); | 790 | kfree(defs); |
791 | ret = ERR_PTR(-ENOMEM); | ||
798 | } | 792 | } |
799 | 793 | ||
800 | return ret; | 794 | return ret; |