요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.
1. 요약·해설
원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.
2. 영어 원문 전체
번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.
원문 전체 펼치기
.. SPDX-License-Identifier: GPL-2.0
=============
Sysfs tagging
=============
(Taken almost verbatim from Eric Biederman's netns tagging patch
commit msg)
The problem. Network devices show up in sysfs and with the network
namespace active multiple devices with the same name can show up in
the same directory, ouch!
To avoid that problem and allow existing applications in network
namespaces to see the same interface that is currently presented in
sysfs, sysfs now has tagging directory support.
By using the network namespace pointers as tags to separate out
the sysfs directory entries we ensure that we don't have conflicts
in the directories and applications only see a limited set of
the network devices.
Each sysfs directory entry may be tagged with a namespace via the
``void *ns member`` of its ``kernfs_node``. If a directory entry is tagged,
then ``kernfs_node->flags`` will have a flag between KOBJ_NS_TYPE_NONE
and KOBJ_NS_TYPES, and ns will point to the namespace to which it
belongs.
Each sysfs superblock's kernfs_super_info contains an array
``void *ns[KOBJ_NS_TYPES]``. When a task in a tagging namespace
kobj_nstype first mounts sysfs, a new superblock is created. It
will be differentiated from other sysfs mounts by having its
``s_fs_info->ns[kobj_nstype]`` set to the new namespace. Note that
through bind mounting and mounts propagation, a task can easily view
the contents of other namespaces' sysfs mounts. Therefore, when a
namespace exits, it will call kobj_ns_exit() to invalidate any
kernfs_node->ns pointers pointing to it.
Users of this interface:
- define a type in the ``kobj_ns_type`` enumeration.
- call kobj_ns_type_register() with its ``kobj_ns_type_operations`` which has
- current_ns() which returns current's namespace
- netlink_ns() which returns a socket's namespace
- initial_ns() which returns the initial namespace
- call kobj_ns_exit() when an individual tag is no longer valid
3. 한국어 전문 번역
영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.
문서 제목과 유래
1-8이 문서는 GPL-2.0 라이선스를 따르며 제목은 ‘Sysfs tagging’입니다.
내용은 Eric Biederman의 network namespace tagging patch commit message에서 거의 그대로 가져왔습니다.
.. SPDX-License-Identifier: GPL-2.0
=============
Sysfs tagging
=============
(Taken almost verbatim from Eric Biederman's netns tagging patch
commit msg)
이름 충돌과 tagging directory
9-20문제는 network device가 sysfs에 나타나는 방식입니다. Network namespace가 활성화되면 이름이 같은 device 여러 개가 같은 directory에 나타날 수 있어 충돌이 발생합니다.
이 문제를 피하면서 network namespace 안의 기존 application이 현재 sysfs에 제시되는 것과 같은 interface를 볼 수 있도록 sysfs는 tagging directory를 지원합니다.
Network namespace pointer를 tag로 사용해 sysfs directory entry를 분리하면 directory 충돌을 막을 수 있고, application에는 해당 namespace에서 허용된 network device 집합만 보입니다.
같은 interface 이름을 namespace tag로 분리합니다.
The problem. Network devices show up in sysfs and with the network
namespace active multiple devices with the same name can show up in
the same directory, ouch!
To avoid that problem and allow existing applications in network
namespaces to see the same interface that is currently presented in
sysfs, sysfs now has tagging directory support.
By using the network namespace pointers as tags to separate out
the sysfs directory entries we ensure that we don't have conflicts
in the directories and applications only see a limited set of
kernfs_node와 superblock namespace
21-36각 sysfs directory entry는 자신의 `kernfs_node`에 있는 `void *ns` member를 통해 namespace tag를 가질 수 있습니다. Entry가 tag되면 `kernfs_node->flags`에는 `KOBJ_NS_TYPE_NONE`과 `KOBJ_NS_TYPES` 사이의 type flag가 들어가고, `ns`는 그 entry가 속한 namespace를 가리킵니다.
각 sysfs superblock의 `kernfs_super_info`에는 `void *ns[KOBJ_NS_TYPES]` array가 있습니다. Tagging namespace type인 `kobj_nstype`에 속한 task가 처음 sysfs를 mount하면 새 superblock이 만들어집니다. 이 superblock은 `s_fs_info->ns[kobj_nstype]`가 새 namespace로 설정되므로 다른 sysfs mount와 구별됩니다.
Bind mount와 mount propagation을 이용하면 task가 다른 namespace의 sysfs mount 내용을 쉽게 볼 수 있습니다. 따라서 namespace가 종료될 때는 `kobj_ns_exit()`를 호출해 그 namespace를 가리키는 모든 `kernfs_node->ns` pointer를 무효화합니다.
Directory entry와 mount가 namespace를 기억하는 위치입니다.
the network devices.
Each sysfs directory entry may be tagged with a namespace via the
``void *ns member`` of its ``kernfs_node``. If a directory entry is tagged,
then ``kernfs_node->flags`` will have a flag between KOBJ_NS_TYPE_NONE
and KOBJ_NS_TYPES, and ns will point to the namespace to which it
belongs.
Each sysfs superblock's kernfs_super_info contains an array
``void *ns[KOBJ_NS_TYPES]``. When a task in a tagging namespace
kobj_nstype first mounts sysfs, a new superblock is created. It
will be differentiated from other sysfs mounts by having its
``s_fs_info->ns[kobj_nstype]`` set to the new namespace. Note that
through bind mounting and mounts propagation, a task can easily view
the contents of other namespaces' sysfs mounts. Therefore, when a
namespace exits, it will call kobj_ns_exit() to invalidate any
Interface 사용 절차
37-48이 interface를 사용하는 subsystem은 다음 절차를 구현합니다.
1. `kobj_ns_type` enumeration에 새 type을 정의합니다.
2. `kobj_ns_type_operations`를 준비해 `kobj_ns_type_register()`로 등록합니다. Operations의 `current_ns()`는 현재 task의 namespace, `netlink_ns()`는 socket의 namespace, `initial_ns()`는 initial namespace를 반환합니다.
3. 개별 tag가 더 이상 유효하지 않을 때 `kobj_ns_exit()`를 호출합니다.
등록 callback과 반환 대상입니다.
kernfs_node->ns pointers pointing to it.
Users of this interface:
- define a type in the ``kobj_ns_type`` enumeration.
- call kobj_ns_type_register() with its ``kobj_ns_type_operations`` which has
- current_ns() which returns current's namespace
- netlink_ns() which returns a socket's namespace
- initial_ns() which returns the initial namespace
- call kobj_ns_exit() when an individual tag is no longer valid
요약·해설
sysfs-tagging.rst:1-48Network namespace마다 같은 이름의 interface가 존재할 수 있으므로 sysfs는 `kernfs_node->ns` tag와 namespace별 superblock view로 entry 충돌을 막습니다. Application은 자신의 namespace에 허용된 device만 보게 됩니다.
Mount는 다른 namespace로 전파되거나 bind될 수 있으므로 namespace 종료 시 `kobj_ns_exit()`로 남은 pointer를 무효화하는 수명 관리가 핵심입니다.
Entry 생성부터 namespace 종료까지의 책임입니다.