* [patch] export, rename fill_kobj_path and get_kobj_path_length
@ 2004-08-06 20:26 Robert Love
2004-08-06 20:41 ` [patch] add kobject_get_path Robert Love
0 siblings, 1 reply; 6+ messages in thread
From: Robert Love @ 2004-08-06 20:26 UTC (permalink / raw)
To: Greg KH; +Cc: linux-kernel
Greg,
Per our discussion, the following patch exports fill_kobj_path and
get_kobj_path_length and adds them to kobject.h.
I also renamed them to kobject_get_path_len and kobject_fill_path,
respectively, to match the name space.
I need these for a kobject-based kevent. Others may find them
fascinating as well.
Robert Love
Export some internal kobject helpers.
Signed-Off-By: Robert Love <rml@ximian.com>
include/linux/kobject.h | 3 +++
lib/kobject.c | 12 +++++++-----
2 files changed, 10 insertions(+), 5 deletions(-)
diff -urN linux-2.6.8-rc3-mm1/include/linux/kobject.h linux-rml/include/linux/kobject.h
--- linux-2.6.8-rc3-mm1/include/linux/kobject.h 2004-08-06 14:03:04.882742673 -0400
+++ linux-rml/include/linux/kobject.h 2004-08-06 15:50:32.518075100 -0400
@@ -58,6 +58,9 @@
extern void kobject_hotplug(const char *action, struct kobject *);
+extern int kobject_get_path_len(struct kset *, struct kobject *);
+extern void kobject_fill_path(struct kset *, struct kobject *, char *, int);
+
struct kobj_type {
void (*release)(struct kobject *);
struct sysfs_ops * sysfs_ops;
diff -urN linux-2.6.8-rc3-mm1/lib/kobject.c linux-rml/lib/kobject.c
--- linux-2.6.8-rc3-mm1/lib/kobject.c 2004-08-06 14:03:06.229569894 -0400
+++ linux-rml/lib/kobject.c 2004-08-06 16:11:14.450737875 -0400
@@ -66,7 +66,7 @@
#ifdef CONFIG_HOTPLUG
-static int get_kobj_path_length(struct kset *kset, struct kobject *kobj)
+int kobject_get_path_len(struct kset *kset, struct kobject *kobj)
{
int length = 1;
struct kobject * parent = kobj;
@@ -82,7 +82,8 @@
return length;
}
-static void fill_kobj_path(struct kset *kset, struct kobject *kobj, char *path, int length)
+void kobject_fill_path(struct kset *kset, struct kobject *kobj, char *path,
+ int length)
{
struct kobject * parent;
@@ -163,12 +164,12 @@
envp [i++] = scratch;
scratch += sprintf(scratch, "SEQNUM=%ld", seq) + 1;
- kobj_path_length = get_kobj_path_length (kset, kobj);
+ kobj_path_length = kobject_get_path_len (kset, kobj);
kobj_path = kmalloc (kobj_path_length, GFP_KERNEL);
if (!kobj_path)
goto exit;
memset (kobj_path, 0x00, kobj_path_length);
- fill_kobj_path (kset, kobj, kobj_path, kobj_path_length);
+ kobject_fill_path (kset, kobj, kobj_path, kobj_path_length);
envp [i++] = scratch;
scratch += sprintf (scratch, "DEVPATH=%s", kobj_path) + 1;
@@ -626,7 +627,8 @@
}
}
-
+EXPORT_SYMBOL(kobject_get_path_len);
+EXPORT_SYMBOL(kobject_fill_path);
EXPORT_SYMBOL(kobject_init);
EXPORT_SYMBOL(kobject_register);
EXPORT_SYMBOL(kobject_unregister);
^ permalink raw reply [flat|nested] 6+ messages in thread
* [patch] add kobject_get_path
2004-08-06 20:26 [patch] export, rename fill_kobj_path and get_kobj_path_length Robert Love
@ 2004-08-06 20:41 ` Robert Love
2004-08-06 20:50 ` Greg KH
0 siblings, 1 reply; 6+ messages in thread
From: Robert Love @ 2004-08-06 20:41 UTC (permalink / raw)
To: Greg KH; +Cc: linux-kernel
Greg -
Hey, here is an alternative to exporting those two functions.
This patch, in lieu, creates a new function that performs the same steps
as in kset_hotplug() and presumably what every single user of the
previously exported functions would do: get the length, allocate memory,
and then build the path.
So just export a single function to do it right. And use it in
kset_hotplug(). The function is prototyped as
char * kobject_get_path(struct kset *kset, struct kobject *kobj,
int gfp_mask)
I like this approach better.
Patch is against 2.6.8-rc3.
Robert Love
Create a new kobject_get_path() helper function, which is super duper.
Signed-Off-By: Robert Love <rml@novell.com>
include/linux/kobject.h | 2 ++
lib/kobject.c | 31 +++++++++++++++++++++++++------
2 files changed, 27 insertions(+), 6 deletions(-)
diff -urN linux-2.6.8-rc3-mm1/include/linux/kobject.h linux/include/linux/kobject.h
--- linux-2.6.8-rc3-mm1/include/linux/kobject.h 2004-08-06 14:03:04.882742673 -0400
+++ linux/include/linux/kobject.h 2004-08-06 16:25:02.797522366 -0400
@@ -58,6 +58,8 @@
extern void kobject_hotplug(const char *action, struct kobject *);
+extern char * kobject_get_path(struct kset *, struct kobject *, int);
+
struct kobj_type {
void (*release)(struct kobject *);
struct sysfs_ops * sysfs_ops;
diff -urN linux-2.6.8-rc3-mm1/lib/kobject.c linux/lib/kobject.c
--- linux-2.6.8-rc3-mm1/lib/kobject.c 2004-08-06 14:03:06.229569894 -0400
+++ linux/lib/kobject.c 2004-08-06 16:36:03.834757764 -0400
@@ -103,6 +103,29 @@
static unsigned long sequence_num;
static spinlock_t sequence_lock = SPIN_LOCK_UNLOCKED;
+/**
+ * kobject_get_path - generate and return the path associated with a given kobj
+ * and kset pair. The result must be freed by the caller with kfree().
+ *
+ * @kset: kset in question, with which to build the path
+ * @kobj: kobject in question, with which to build the path
+ * @gfp_mask: the allocation type used to allocate the path
+ */
+char * kobject_get_path(struct kset *kset, struct kobject *kobj, int gfp_mask)
+{
+ char *path;
+ int len;
+
+ len = get_kobj_path_length (kset, kobj);
+ path = kmalloc (len, gfp_mask);
+ if (!path)
+ return NULL;
+ memset (path, 0x00, len);
+ fill_kobj_path (kset, kobj, path, len);
+
+ return path;
+}
+
static void kset_hotplug(const char *action, struct kset *kset,
struct kobject *kobj)
{
@@ -112,7 +135,6 @@
char *scratch;
int i = 0;
int retval;
- int kobj_path_length;
char *kobj_path = NULL;
char *name = NULL;
unsigned long seq;
@@ -163,12 +185,9 @@
envp [i++] = scratch;
scratch += sprintf(scratch, "SEQNUM=%ld", seq) + 1;
- kobj_path_length = get_kobj_path_length (kset, kobj);
- kobj_path = kmalloc (kobj_path_length, GFP_KERNEL);
+ kobj_path = kobject_get_path (kset, kobj, GFP_KERNEL);
if (!kobj_path)
goto exit;
- memset (kobj_path, 0x00, kobj_path_length);
- fill_kobj_path (kset, kobj, kobj_path, kobj_path_length);
envp [i++] = scratch;
scratch += sprintf (scratch, "DEVPATH=%s", kobj_path) + 1;
@@ -626,7 +645,7 @@
}
}
-
+EXPORT_SYMBOL(kobject_get_path);
EXPORT_SYMBOL(kobject_init);
EXPORT_SYMBOL(kobject_register);
EXPORT_SYMBOL(kobject_unregister);
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch] add kobject_get_path
2004-08-06 20:41 ` [patch] add kobject_get_path Robert Love
@ 2004-08-06 20:50 ` Greg KH
2004-08-06 20:56 ` Robert Love
0 siblings, 1 reply; 6+ messages in thread
From: Greg KH @ 2004-08-06 20:50 UTC (permalink / raw)
To: Robert Love; +Cc: linux-kernel
On Fri, Aug 06, 2004 at 04:41:43PM -0400, Robert Love wrote:
> Greg -
>
> Hey, here is an alternative to exporting those two functions.
Ah, good timing, I was just about to apply your other patch :)
>
> This patch, in lieu, creates a new function that performs the same steps
> as in kset_hotplug() and presumably what every single user of the
> previously exported functions would do: get the length, allocate memory,
> and then build the path.
>
> So just export a single function to do it right. And use it in
> kset_hotplug(). The function is prototyped as
>
> char * kobject_get_path(struct kset *kset, struct kobject *kobj,
> int gfp_mask)
>
> I like this approach better.
I do too. One problem though, get_kobj_path_length and fill_kobj_path
are only built if CONFIG_HOTPLUG is enabled. Care to respin this patch
by moving the functions outside of that #define?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch] add kobject_get_path
2004-08-06 20:50 ` Greg KH
@ 2004-08-06 20:56 ` Robert Love
2004-08-06 21:07 ` Robert Love
2004-08-06 21:16 ` Greg KH
0 siblings, 2 replies; 6+ messages in thread
From: Robert Love @ 2004-08-06 20:56 UTC (permalink / raw)
To: Greg KH; +Cc: linux-kernel
On Fri, 2004-08-06 at 13:50 -0700, Greg KH wrote:
> I do too. One problem though, get_kobj_path_length and fill_kobj_path
> are only built if CONFIG_HOTPLUG is enabled. Care to respin this patch
> by moving the functions outside of that #define?
Hrm, did not notice that. kobject_get_path() was inside there, too.
I presume these functions are still meaningful if !CONFIG_HOTPLUG?
Here we go. Thanks,
Robert Love
Add a new kobject helper, kobject_get_path(), which is the greatest
function ever.
Signed-Off-By: Robert Love <rml@ximian.com>
include/linux/kobject.h | 2 ++
lib/kobject.c | 36 +++++++++++++++++++++++++++---------
2 files changed, 29 insertions(+), 9 deletions(-)
diff -urN linux-2.6.8-rc3-mm1/include/linux/kobject.h linux/include/linux/kobject.h
--- linux-2.6.8-rc3-mm1/include/linux/kobject.h 2004-08-06 14:03:04.882742673 -0400
+++ linux/include/linux/kobject.h 2004-08-06 16:25:02.797522366 -0400
@@ -58,6 +58,8 @@
extern void kobject_hotplug(const char *action, struct kobject *);
+extern char * kobject_get_path(struct kset *, struct kobject *, int);
+
struct kobj_type {
void (*release)(struct kobject *);
struct sysfs_ops * sysfs_ops;
diff -urN linux-2.6.8-rc3-mm1/lib/kobject.c linux/lib/kobject.c
--- linux-2.6.8-rc3-mm1/lib/kobject.c 2004-08-06 14:03:06.229569894 -0400
+++ linux/lib/kobject.c 2004-08-06 16:53:24.484278248 -0400
@@ -58,14 +58,11 @@
return error;
}
-
static inline struct kobject * to_kobj(struct list_head * entry)
{
return container_of(entry,struct kobject,entry);
}
-
-#ifdef CONFIG_HOTPLUG
static int get_kobj_path_length(struct kset *kset, struct kobject *kobj)
{
int length = 1;
@@ -98,6 +95,31 @@
pr_debug("%s: path = '%s'\n",__FUNCTION__,path);
}
+/**
+ * kobject_get_path - generate and return the path associated with a given kobj
+ * and kset pair. The result must be freed by the caller with kfree().
+ *
+ * @kset: kset in question, with which to build the path
+ * @kobj: kobject in question, with which to build the path
+ * @gfp_mask: the allocation type used to allocate the path
+ */
+char * kobject_get_path(struct kset *kset, struct kobject *kobj, int gfp_mask)
+{
+ char *path;
+ int len;
+
+ len = get_kobj_path_length (kset, kobj);
+ path = kmalloc (len, gfp_mask);
+ if (!path)
+ return NULL;
+ memset (path, 0x00, len);
+ fill_kobj_path (kset, kobj, path, len);
+
+ return path;
+}
+
+#ifdef CONFIG_HOTPLUG
+
#define BUFFER_SIZE 1024 /* should be enough memory for the env */
#define NUM_ENVP 32 /* number of env pointers */
static unsigned long sequence_num;
@@ -112,7 +134,6 @@
char *scratch;
int i = 0;
int retval;
- int kobj_path_length;
char *kobj_path = NULL;
char *name = NULL;
unsigned long seq;
@@ -163,12 +184,9 @@
envp [i++] = scratch;
scratch += sprintf(scratch, "SEQNUM=%ld", seq) + 1;
- kobj_path_length = get_kobj_path_length (kset, kobj);
- kobj_path = kmalloc (kobj_path_length, GFP_KERNEL);
+ kobj_path = kobject_get_path (kset, kobj, GFP_KERNEL);
if (!kobj_path)
goto exit;
- memset (kobj_path, 0x00, kobj_path_length);
- fill_kobj_path (kset, kobj, kobj_path, kobj_path_length);
envp [i++] = scratch;
scratch += sprintf (scratch, "DEVPATH=%s", kobj_path) + 1;
@@ -626,7 +644,7 @@
}
}
-
+EXPORT_SYMBOL(kobject_get_path);
EXPORT_SYMBOL(kobject_init);
EXPORT_SYMBOL(kobject_register);
EXPORT_SYMBOL(kobject_unregister);
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch] add kobject_get_path
2004-08-06 20:56 ` Robert Love
@ 2004-08-06 21:07 ` Robert Love
2004-08-06 21:16 ` Greg KH
1 sibling, 0 replies; 6+ messages in thread
From: Robert Love @ 2004-08-06 21:07 UTC (permalink / raw)
To: Greg KH; +Cc: linux-kernel
On Fri, 2004-08-06 at 16:56 -0400, Robert Love wrote:
> I presume these functions are still meaningful if !CONFIG_HOTPLUG?
Compiles, at least. Just tested.
Robert Love
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [patch] add kobject_get_path
2004-08-06 20:56 ` Robert Love
2004-08-06 21:07 ` Robert Love
@ 2004-08-06 21:16 ` Greg KH
1 sibling, 0 replies; 6+ messages in thread
From: Greg KH @ 2004-08-06 21:16 UTC (permalink / raw)
To: Robert Love; +Cc: linux-kernel
On Fri, Aug 06, 2004 at 04:56:03PM -0400, Robert Love wrote:
> On Fri, 2004-08-06 at 13:50 -0700, Greg KH wrote:
>
> > I do too. One problem though, get_kobj_path_length and fill_kobj_path
> > are only built if CONFIG_HOTPLUG is enabled. Care to respin this patch
> > by moving the functions outside of that #define?
>
> Hrm, did not notice that. kobject_get_path() was inside there, too.
>
> I presume these functions are still meaningful if !CONFIG_HOTPLUG?
Well, they weren't until your function needed them :)
> Here we go. Thanks,
Applied, thanks.
greg k-h
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2004-08-06 21:21 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-08-06 20:26 [patch] export, rename fill_kobj_path and get_kobj_path_length Robert Love
2004-08-06 20:41 ` [patch] add kobject_get_path Robert Love
2004-08-06 20:50 ` Greg KH
2004-08-06 20:56 ` Robert Love
2004-08-06 21:07 ` Robert Love
2004-08-06 21:16 ` Greg KH
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.