6 The layout of a file controls how its contents are mapped to Ceph RADOS objects. You can
7 read and write a file's layout using *virtual extended attributes* or xattrs.
9 The name of the layout xattrs depends on whether a file is a regular file or a directory. Regular
10 files' layout xattrs are called ``ceph.file.layout``, whereas directories' layout xattrs are called
11 ``ceph.dir.layout``. Where subsequent examples refer to ``ceph.file.layout``, substitute ``dir`` as appropriate
12 when dealing with directories.
16 Your linux distribution may not ship with commands for manipulating xattrs by default,
17 the required package is usually called ``attr``.
23 String, giving ID or name. Which RADOS pool a file's data objects will be stored in.
26 String. Within the data pool, which RADOS namespace the objects will
27 be written to. Empty by default (i.e. default namespace).
30 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.
33 Integer. The number of consecutive stripe units that constitute a RAID 0 “stripe” of file data.
36 Integer in bytes. File data is chunked into RADOS objects of this size.
40 RADOS enforces a configurable limit on object sizes: if you increase CephFS
41 object sizes beyond that limit then writes may not succeed. The OSD
42 setting is ``osd_max_object_size``, which is 128MB by default.
43 Very large RADOS objects may prevent smooth operation of the cluster,
44 so increasing the object size limit past the default is not recommended.
46 Reading layouts with ``getfattr``
47 ---------------------------------
49 Read the layout information as a single string:
54 $ getfattr -n ceph.file.layout file
56 ceph.file.layout="stripe_unit=4194304 stripe_count=1 object_size=4194304 pool=cephfs_data"
58 Read individual layout fields:
62 $ getfattr -n ceph.file.layout.pool file
64 ceph.file.layout.pool="cephfs_data"
65 $ getfattr -n ceph.file.layout.stripe_unit file
67 ceph.file.layout.stripe_unit="4194304"
68 $ getfattr -n ceph.file.layout.stripe_count file
70 ceph.file.layout.stripe_count="1"
71 $ getfattr -n ceph.file.layout.object_size file
73 ceph.file.layout.object_size="4194304"
77 When reading layouts, the pool will usually be indicated by name. However, in
78 rare cases when pools have only just been created, the ID may be output instead.
80 Directories do not have an explicit layout until it is customized. Attempts to read
81 the layout will fail if it has never been modified: this indicates that layout of the
82 next ancestor directory with an explicit layout will be used.
87 $ getfattr -n ceph.dir.layout dir
88 dir: ceph.dir.layout: No such attribute
89 $ setfattr -n ceph.dir.layout.stripe_count -v 2 dir
90 $ getfattr -n ceph.dir.layout dir
92 ceph.dir.layout="stripe_unit=4194304 stripe_count=2 object_size=4194304 pool=cephfs_data"
95 Writing layouts with ``setfattr``
96 ---------------------------------
98 Layout fields are modified using ``setfattr``:
107 $ setfattr -n ceph.file.layout.stripe_unit -v 1048576 file2
108 $ setfattr -n ceph.file.layout.stripe_count -v 8 file2
109 $ setfattr -n ceph.file.layout.object_size -v 10485760 file2
110 $ setfattr -n ceph.file.layout.pool -v 1 file2 # Setting pool by ID
111 $ setfattr -n ceph.file.layout.pool -v cephfs_data file2 # Setting pool by name
115 When the layout fields of a file are modified using ``setfattr``, this file must be empty, otherwise an error will occur.
119 # touch an empty file
121 # modify layout field successfully
122 $ setfattr -n ceph.file.layout.stripe_count -v 3 file1
124 # write something to file1
125 $ echo "hello world" > file1
126 $ setfattr -n ceph.file.layout.stripe_count -v 4 file1
127 setfattr: file1: Directory not empty
132 If you wish to remove an explicit layout from a directory, to revert to
133 inheriting the layout of its ancestor, you can do so:
137 setfattr -x ceph.dir.layout mydir
139 Similarly, if you have set the ``pool_namespace`` attribute and wish
140 to modify the layout to use the default namespace instead:
144 # Create a dir and set a namespace on it
146 setfattr -n ceph.dir.layout.pool_namespace -v foons mydir
147 getfattr -n ceph.dir.layout mydir
148 ceph.dir.layout="stripe_unit=4194304 stripe_count=1 object_size=4194304 pool=cephfs_data_a pool_namespace=foons"
150 # Clear the namespace from the directory's layout
151 setfattr -x ceph.dir.layout.pool_namespace mydir
152 getfattr -n ceph.dir.layout mydir
153 ceph.dir.layout="stripe_unit=4194304 stripe_count=1 object_size=4194304 pool=cephfs_data_a"
156 Inheritance of layouts
157 ----------------------
159 Files inherit the layout of their parent directory at creation time. However, subsequent
160 changes to the parent directory's layout do not affect children.
164 $ getfattr -n ceph.dir.layout dir
166 ceph.dir.layout="stripe_unit=4194304 stripe_count=2 object_size=4194304 pool=cephfs_data"
168 # Demonstrate file1 inheriting its parent's layout
170 $ getfattr -n ceph.file.layout dir/file1
172 ceph.file.layout="stripe_unit=4194304 stripe_count=2 object_size=4194304 pool=cephfs_data"
174 # Now update the layout of the directory before creating a second file
175 $ setfattr -n ceph.dir.layout.stripe_count -v 4 dir
178 # Demonstrate that file1's layout is unchanged
179 $ getfattr -n ceph.file.layout dir/file1
181 ceph.file.layout="stripe_unit=4194304 stripe_count=2 object_size=4194304 pool=cephfs_data"
183 # ...while file2 has the parent directory's new layout
184 $ getfattr -n ceph.file.layout dir/file2
186 ceph.file.layout="stripe_unit=4194304 stripe_count=4 object_size=4194304 pool=cephfs_data"
189 Files created as descendents of the directory also inherit the layout, if the intermediate
190 directories do not have layouts set:
194 $ getfattr -n ceph.dir.layout dir
196 ceph.dir.layout="stripe_unit=4194304 stripe_count=4 object_size=4194304 pool=cephfs_data"
198 $ getfattr -n ceph.dir.layout dir/childdir
199 dir/childdir: ceph.dir.layout: No such attribute
200 $ touch dir/childdir/grandchild
201 $ getfattr -n ceph.file.layout dir/childdir/grandchild
202 # file: dir/childdir/grandchild
203 ceph.file.layout="stripe_unit=4194304 stripe_count=4 object_size=4194304 pool=cephfs_data"
206 Adding a data pool to the MDS
207 -----------------------------
209 Before you can use a pool with CephFS you have to add it to the Metadata Servers.
213 $ ceph fs add_data_pool cephfs cephfs_data_ssd
214 $ ceph fs ls # Pool should now show up
215 .... data pools: [cephfs_data cephfs_data_ssd ]
217 Make sure that your cephx keys allows the client to access this new pool.
219 You can then update the layout on a directory in CephFS to use the pool you added:
223 $ mkdir /mnt/cephfs/myssddir
224 $ setfattr -n ceph.dir.layout.pool -v cephfs_data_ssd /mnt/cephfs/myssddir
226 All new files created within that directory will now inherit its layout and place their data in your newly added pool.
228 You may notice that object counts in your primary data pool (the one passed to ``fs new``) continue to increase, even if files are being created in the pool you added. This is normal: the file data is stored in the pool specified by the layout, but a small amount of metadata is kept in the primary data pool for all files.