Commit 571dba52a34015a5a7aa5d480a86936878444a6f
Committed by
Sage Weil
1 parent
010e3b48fc
Exists in
master
and in
4 other branches
ceph: add CEPH_MDS_OP_SETDIRLAYOUT and associated ioctl.
Signed-off-by: Sage Weil <sage@newdream.net>
Showing 3 changed files with 70 additions and 1 deletions Side-by-side Diff
fs/ceph/ioctl.c
... | ... | @@ -92,6 +92,68 @@ |
92 | 92 | } |
93 | 93 | |
94 | 94 | /* |
95 | + * Set a layout policy on a directory inode. All items in the tree | |
96 | + * rooted at this inode will inherit this layout on creation, | |
97 | + * (It doesn't apply retroactively ) | |
98 | + * unless a subdirectory has its own layout policy. | |
99 | + */ | |
100 | +static long ceph_ioctl_set_layout_policy (struct file *file, void __user *arg) | |
101 | +{ | |
102 | + struct inode *inode = file->f_dentry->d_inode; | |
103 | + struct ceph_mds_request *req; | |
104 | + struct ceph_ioctl_layout l; | |
105 | + int err, i; | |
106 | + struct ceph_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc; | |
107 | + | |
108 | + /* copy and validate */ | |
109 | + if (copy_from_user(&l, arg, sizeof(l))) | |
110 | + return -EFAULT; | |
111 | + | |
112 | + if ((l.object_size & ~PAGE_MASK) || | |
113 | + (l.stripe_unit & ~PAGE_MASK) || | |
114 | + !l.stripe_unit || | |
115 | + (l.object_size && | |
116 | + (unsigned)l.object_size % (unsigned)l.stripe_unit)) | |
117 | + return -EINVAL; | |
118 | + | |
119 | + /* make sure it's a valid data pool */ | |
120 | + if (l.data_pool > 0) { | |
121 | + mutex_lock(&mdsc->mutex); | |
122 | + err = -EINVAL; | |
123 | + for (i = 0; i < mdsc->mdsmap->m_num_data_pg_pools; i++) | |
124 | + if (mdsc->mdsmap->m_data_pg_pools[i] == l.data_pool) { | |
125 | + err = 0; | |
126 | + break; | |
127 | + } | |
128 | + mutex_unlock(&mdsc->mutex); | |
129 | + if (err) | |
130 | + return err; | |
131 | + } | |
132 | + | |
133 | + req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SETDIRLAYOUT, | |
134 | + USE_AUTH_MDS); | |
135 | + | |
136 | + if (IS_ERR(req)) | |
137 | + return PTR_ERR(req); | |
138 | + req->r_inode = igrab(inode); | |
139 | + | |
140 | + req->r_args.setlayout.layout.fl_stripe_unit = | |
141 | + cpu_to_le32(l.stripe_unit); | |
142 | + req->r_args.setlayout.layout.fl_stripe_count = | |
143 | + cpu_to_le32(l.stripe_count); | |
144 | + req->r_args.setlayout.layout.fl_object_size = | |
145 | + cpu_to_le32(l.object_size); | |
146 | + req->r_args.setlayout.layout.fl_pg_pool = | |
147 | + cpu_to_le32(l.data_pool); | |
148 | + req->r_args.setlayout.layout.fl_pg_preferred = | |
149 | + cpu_to_le32(l.preferred_osd); | |
150 | + | |
151 | + err = ceph_mdsc_do_request(mdsc, inode, req); | |
152 | + ceph_mdsc_put_request(req); | |
153 | + return err; | |
154 | +} | |
155 | + | |
156 | +/* | |
95 | 157 | * Return object name, size/offset information, and location (OSD |
96 | 158 | * number, network address) for a given file offset. |
97 | 159 | */ |
98 | 160 | |
... | ... | @@ -177,12 +239,16 @@ |
177 | 239 | case CEPH_IOC_SET_LAYOUT: |
178 | 240 | return ceph_ioctl_set_layout(file, (void __user *)arg); |
179 | 241 | |
242 | + case CEPH_IOC_SET_LAYOUT_POLICY: | |
243 | + return ceph_ioctl_set_layout_policy(file, (void __user *)arg); | |
244 | + | |
180 | 245 | case CEPH_IOC_GET_DATALOC: |
181 | 246 | return ceph_ioctl_get_dataloc(file, (void __user *)arg); |
182 | 247 | |
183 | 248 | case CEPH_IOC_LAZYIO: |
184 | 249 | return ceph_ioctl_lazyio(file); |
185 | 250 | } |
251 | + | |
186 | 252 | return -ENOTTY; |
187 | 253 | } |
fs/ceph/ioctl.h
... | ... | @@ -4,7 +4,7 @@ |
4 | 4 | #include <linux/ioctl.h> |
5 | 5 | #include <linux/types.h> |
6 | 6 | |
7 | -#define CEPH_IOCTL_MAGIC 0x97 | |
7 | +#define CEPH_IOCTL_MAGIC 0x98 | |
8 | 8 | |
9 | 9 | /* just use u64 to align sanely on all archs */ |
10 | 10 | struct ceph_ioctl_layout { |
... | ... | @@ -16,6 +16,8 @@ |
16 | 16 | #define CEPH_IOC_GET_LAYOUT _IOR(CEPH_IOCTL_MAGIC, 1, \ |
17 | 17 | struct ceph_ioctl_layout) |
18 | 18 | #define CEPH_IOC_SET_LAYOUT _IOW(CEPH_IOCTL_MAGIC, 2, \ |
19 | + struct ceph_ioctl_layout) | |
20 | +#define CEPH_IOC_SET_LAYOUT_POLICY _IOW(CEPH_IOCTL_MAGIC, 5, \ | |
19 | 21 | struct ceph_ioctl_layout) |
20 | 22 | |
21 | 23 | /* |
include/linux/ceph/ceph_fs.h