]> git.proxmox.com Git - ceph.git/blame - ceph/doc/cephfs/file-layouts.rst
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / doc / cephfs / file-layouts.rst
CommitLineData
7c673cae
FG
1
2File layouts
3============
4
5The layout of a file controls how its contents are mapped to Ceph RADOS objects. You can
6read and write a file's layout using *virtual extended attributes* or xattrs.
7
8The name of the layout xattrs depends on whether a file is a regular file or a directory. Regular
9files' layout xattrs are called ``ceph.file.layout``, whereas directories' layout xattrs are called
10``ceph.dir.layout``. Where subsequent examples refer to ``ceph.file.layout``, substitute ``dir`` as appropriate
11when dealing with directories.
12
13.. tip::
14
15 Your linux distribution may not ship with commands for manipulating xattrs by default,
16 the required package is usually called ``attr``.
17
18Layout fields
19-------------
20
21pool
22 String, giving ID or name. Which RADOS pool a file's data objects will be stored in.
23
24pool_namespace
25 String. Within the data pool, which RADOS namespace the objects will
26 be written to. Empty by default (i.e. default namespace).
27
28stripe_unit
29 Integer in bytes. The size (in bytes) of a block of data used in the RAID 0 distribution of a file. All stripe units for a file have equal size. The last stripe unit is typically incomplete–i.e. it represents the data at the end of the file as well as unused “space” beyond it up to the end of the fixed stripe unit size.
30
31stripe_count
32 Integer. The number of consecutive stripe units that constitute a RAID 0 “stripe” of file data.
33
34object_size
35 Integer in bytes. File data is chunked into RADOS objects of this size.
36
37Reading layouts with ``getfattr``
38---------------------------------
39
40Read the layout information as a single string:
41
42.. code-block:: bash
43
44 $ touch file
45 $ getfattr -n ceph.file.layout file
46 # file: file
47 ceph.file.layout="stripe_unit=4194304 stripe_count=1 object_size=4194304 pool=cephfs_data"
48
49Read individual layout fields:
50
51.. code-block:: bash
52
53 $ getfattr -n ceph.file.layout.pool file
54 # file: file
55 ceph.file.layout.pool="cephfs_data"
56 $ getfattr -n ceph.file.layout.stripe_unit file
57 # file: file
58 ceph.file.layout.stripe_unit="4194304"
59 $ getfattr -n ceph.file.layout.stripe_count file
60 # file: file
61 ceph.file.layout.stripe_count="1"
62 $ getfattr -n ceph.file.layout.object_size file
63 # file: file
64 ceph.file.layout.object_size="4194304"
65
66.. note::
67
68 When reading layouts, the pool will usually be indicated by name. However, in
69 rare cases when pools have only just been created, the ID may be output instead.
70
71Directories do not have an explicit layout until it is customized. Attempts to read
72the layout will fail if it has never been modified: this indicates that layout of the
73next ancestor directory with an explicit layout will be used.
74
75.. code-block:: bash
76
77 $ mkdir dir
78 $ getfattr -n ceph.dir.layout dir
79 dir: ceph.dir.layout: No such attribute
80 $ setfattr -n ceph.dir.layout.stripe_count -v 2 dir
81 $ getfattr -n ceph.dir.layout dir
82 # file: dir
83 ceph.dir.layout="stripe_unit=4194304 stripe_count=2 object_size=4194304 pool=cephfs_data"
84
85
86Writing layouts with ``setfattr``
87---------------------------------
88
89Layout fields are modified using ``setfattr``:
90
91.. code-block:: bash
92
93 $ ceph osd lspools
94 0 rbd,1 cephfs_data,2 cephfs_metadata,
95
96 $ setfattr -n ceph.file.layout.stripe_unit -v 1048576 file2
97 $ setfattr -n ceph.file.layout.stripe_count -v 8 file2
98 $ setfattr -n ceph.file.layout.object_size -v 10485760 file2
99 $ setfattr -n ceph.file.layout.pool -v 1 file2 # Setting pool by ID
100 $ setfattr -n ceph.file.layout.pool -v cephfs_data file2 # Setting pool by name
101
102.. note::
103
104 When the layout fields of a file are modified using ``setfattr``, this file must be empty, otherwise an error will occur.
105
106.. code-block:: bash
107
108 # touch an empty file
109 $ touch file1
110 # modify layout field successfully
111 $ setfattr -n ceph.file.layout.stripe_count -v 3 file1
112
113 # write something to file1
114 $ echo "hello world" > file1
115 $ setfattr -n ceph.file.layout.stripe_count -v 4 file1
116 setfattr: file1: Directory not empty
117
118Clearing layouts
119----------------
120
121If you wish to remove an explicit layout from a directory, to revert to
122inherting the layout of its ancestor, you can do so:
123
124.. code-block:: bash
125
126 setfattr -x ceph.dir.layout mydir
127
128Similarly, if you have set the ``pool_namespace`` attribute and wish
129to modify the layout to use the default namespace instead:
130
131.. code-block:: bash
132
133 # Create a dir and set a namespace on it
134 mkdir mydir
135 setfattr -n ceph.dir.layout.pool_namespace -v foons mydir
136 getfattr -n ceph.dir.layout mydir
137 ceph.dir.layout="stripe_unit=4194304 stripe_count=1 object_size=4194304 pool=cephfs_data_a pool_namespace=foons"
138
139 # Clear the namespace from the directory's layout
140 setfattr -x ceph.dir.layout.pool_namespace mydir
141 getfattr -n ceph.dir.layout mydir
142 ceph.dir.layout="stripe_unit=4194304 stripe_count=1 object_size=4194304 pool=cephfs_data_a"
143
144
145Inheritance of layouts
146----------------------
147
148Files inherit the layout of their parent directory at creation time. However, subsequent
149changes to the parent directory's layout do not affect children.
150
151.. code-block:: bash
152
153 $ getfattr -n ceph.dir.layout dir
154 # file: dir
155 ceph.dir.layout="stripe_unit=4194304 stripe_count=2 object_size=4194304 pool=cephfs_data"
156
157 # Demonstrate file1 inheriting its parent's layout
158 $ touch dir/file1
159 $ getfattr -n ceph.file.layout dir/file1
160 # file: dir/file1
161 ceph.file.layout="stripe_unit=4194304 stripe_count=2 object_size=4194304 pool=cephfs_data"
162
163 # Now update the layout of the directory before creating a second file
164 $ setfattr -n ceph.dir.layout.stripe_count -v 4 dir
165 $ touch dir/file2
166
167 # Demonstrate that file1's layout is unchanged
168 $ getfattr -n ceph.file.layout dir/file1
169 # file: dir/file1
170 ceph.file.layout="stripe_unit=4194304 stripe_count=2 object_size=4194304 pool=cephfs_data"
171
172 # ...while file2 has the parent directory's new layout
173 $ getfattr -n ceph.file.layout dir/file2
174 # file: dir/file2
175 ceph.file.layout="stripe_unit=4194304 stripe_count=4 object_size=4194304 pool=cephfs_data"
176
177
178Files created as descendents of the directory also inherit the layout, if the intermediate
179directories do not have layouts set:
180
181.. code-block:: bash
182
183 $ getfattr -n ceph.dir.layout dir
184 # file: dir
185 ceph.dir.layout="stripe_unit=4194304 stripe_count=4 object_size=4194304 pool=cephfs_data"
186 $ mkdir dir/childdir
187 $ getfattr -n ceph.dir.layout dir/childdir
188 dir/childdir: ceph.dir.layout: No such attribute
189 $ touch dir/childdir/grandchild
190 $ getfattr -n ceph.file.layout dir/childdir/grandchild
191 # file: dir/childdir/grandchild
192 ceph.file.layout="stripe_unit=4194304 stripe_count=4 object_size=4194304 pool=cephfs_data"
193
194
195Adding a data pool to the MDS
196---------------------------------
197
198Before you can use a pool with CephFS you have to add it to the Metadata Servers.
199
200.. code-block:: bash
201
202 $ ceph fs add_data_pool cephfs cephfs_data_ssd
203 # Pool should now show up
204 $ ceph fs ls
205 .... data pools: [cephfs_data cephfs_data_ssd ]
206
207Make sure that your cephx keys allows the client to access this new pool.