sysfs-tagging.txt 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. Sysfs tagging
  2. -------------
  3. (Taken almost verbatim from Eric Biederman's netns tagging patch
  4. commit msg)
  5. The problem. Network devices show up in sysfs and with the network
  6. namespace active multiple devices with the same name can show up in
  7. the same directory, ouch!
  8. To avoid that problem and allow existing applications in network
  9. namespaces to see the same interface that is currently presented in
  10. sysfs, sysfs now has tagging directory support.
  11. By using the network namespace pointers as tags to separate out the
  12. the sysfs directory entries we ensure that we don't have conflicts
  13. in the directories and applications only see a limited set of
  14. the network devices.
  15. Each sysfs directory entry may be tagged with a namespace via the
  16. void *ns member of its kernfs_node. If a directory entry is tagged,
  17. then kernfs_node->flags will have a flag between KOBJ_NS_TYPE_NONE
  18. and KOBJ_NS_TYPES, and ns will point to the namespace to which it
  19. belongs.
  20. Each sysfs superblock's kernfs_super_info contains an array void
  21. *ns[KOBJ_NS_TYPES]. When a task in a tagging namespace
  22. kobj_nstype first mounts sysfs, a new superblock is created. It
  23. will be differentiated from other sysfs mounts by having its
  24. s_fs_info->ns[kobj_nstype] set to the new namespace. Note that
  25. through bind mounting and mounts propagation, a task can easily view
  26. the contents of other namespaces' sysfs mounts. Therefore, when a
  27. namespace exits, it will call kobj_ns_exit() to invalidate any
  28. kernfs_node->ns pointers pointing to it.
  29. Users of this interface:
  30. - define a type in the kobj_ns_type enumeration.
  31. - call kobj_ns_type_register() with its kobj_ns_type_operations which has
  32. - current_ns() which returns current's namespace
  33. - netlink_ns() which returns a socket's namespace
  34. - initial_ns() which returns the initial namesapce
  35. - call kobj_ns_exit() when an individual tag is no longer valid