[PATCH] Documentation: Add section to kobject.txt showing initial kobjects.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add a bit of a digression, showing readers where the very first
kobjects come from.

Signed-off-by: Robert P. J. Day <rpjday@xxxxxxxxxxxxxx>

---

  it's entirely possible that explaining the very first kobjects is
outside the scope of kobject.txt, so i'll let gregkh ack or nak this
patch, it's entirely up to him and i'm fine either way.

diff --git a/Documentation/kobject.txt b/Documentation/kobject.txt
index 49578cf..061e85d 100644
--- a/Documentation/kobject.txt
+++ b/Documentation/kobject.txt
@@ -234,6 +234,50 @@ See the example module, samples/kobject/kobject-example.c for an
 implementation of a simple kobject and attributes.


+SIDE NOTE: Where do all those initial kobjects come from, anyway?
+
+Since you're invariably creating new kobjects as children of existing
+kobjects, it can be informative to see where the very first kobjects
+come from.  You can see the contents of the top of the /sys filesystem
+and its standard directories:
+
+$ ls /sys
+block  bus  class  dev  devices  firmware  fs  hypervisor  kernel  module  power
+$
+
+Each of those directories is typically represented by a static kobject,
+some of whose declarations you can see in <linux/kobject.h>:
+
+    /* The global /sys/kernel/ kobject for people to chain off of */
+    extern struct kobject *kernel_kobj;
+    /* The global /sys/kernel/mm/ kobject for people to chain off of */
+    extern struct kobject *mm_kobj;
+    /* The global /sys/hypervisor/ kobject for people to chain off of */
+    extern struct kobject *hypervisor_kobj;
+    /* The global /sys/power/ kobject for people to chain off of */
+    extern struct kobject *power_kobj;
+    /* The global /sys/firmware/ kobject for people to chain off of */
+    extern struct kobject *firmware_kobj;
+
+and each of those top-level kobjects will typically be created and
+initialized in the appropriate file in drivers/base/*.c.  For example,
+here's the hypervisor kobject being created and added in the source file
+drivers/base/hypervisor.c:
+
+    struct kobject *hypervisor_kobj;
+    EXPORT_SYMBOL_GPL(hypervisor_kobj);
+
+    int __init hypervisor_init(void)
+    {
+            hypervisor_kobj = kobject_create_and_add("hypervisor", NULL);
+            if (!hypervisor_kobj)
+                    return -ENOMEM;
+            return 0;
+    }
+
+It is left as an exercise for the reader to track down where the rest of
+the top-level kobjects are created and added.
+

 ktypes and release methods


-- 

========================================================================
Robert P. J. Day                                 Ottawa, Ontario, CANADA
                        http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================
--
To unsubscribe from this list: send the line "unsubscribe linux-doc" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux