← Documents Documentation/networking/sysfs-tagging.rst GitHub 원문 ↗

Linux 6.18.37 · Networking

Sysfs tagging

Network namespace별 sysfs entry와 mount를 namespace tag로 분리하고 수명을 정리하는 kernfs interface입니다.

Source pathDocumentation/networking/sysfs-tagging.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

sysfs-tagging.rst:1-48

Network namespace마다 같은 이름의 interface가 존재할 수 있으므로 sysfs는 `kernfs_node->ns` tag와 namespace별 superblock view로 entry 충돌을 막습니다. Application은 자신의 namespace에 허용된 device만 보게 됩니다.

Mount는 다른 namespace로 전파되거나 bind될 수 있으므로 namespace 종료 시 `kobj_ns_exit()`로 남은 pointer를 무효화하는 수명 관리가 핵심입니다.

Tag와 수명
kobj_ns_type 등록Namespace별 sysfs mountkernfs_node tag로 view 제한Namespace 종료kobj_ns_exit()

Entry 생성부터 namespace 종료까지의 책임입니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

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

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 집합만 보입니다.

sysfs namespace view
Network devicekernfs_node namespace tagNamespace별 sysfs directory entryApplication에 제한된 device view

같은 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를 무효화합니다.

Tagging 내부 상태
대상namespace 저장 위치수명 처리
sysfs directory entrykernfs_node->ns + type flagnamespace 종료 시 pointer 무효화
sysfs superblocks_fs_info->ns[kobj_nstype]namespace별 최초 mount에서 생성
namespacetag identitykobj_ns_exit() 호출

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()`를 호출합니다.

kobj namespace operation
Callback반환 대상
current_ns()현재 task의 namespace
netlink_ns()socket의 namespace
initial_ns()initial namespace

등록 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