]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - fs/ceph/ioctl.c
ceph: drop support for preferred_osd pgs
[mirror_ubuntu-bionic-kernel.git] / fs / ceph / ioctl.c
1 #include <linux/in.h>
2
3 #include "super.h"
4 #include "mds_client.h"
5 #include <linux/ceph/ceph_debug.h>
6
7 #include "ioctl.h"
8
9
10 /*
11 * ioctls
12 */
13
14 /*
15 * get and set the file layout
16 */
17 static long ceph_ioctl_get_layout(struct file *file, void __user *arg)
18 {
19 struct ceph_inode_info *ci = ceph_inode(file->f_dentry->d_inode);
20 struct ceph_ioctl_layout l;
21 int err;
22
23 err = ceph_do_getattr(file->f_dentry->d_inode, CEPH_STAT_CAP_LAYOUT);
24 if (!err) {
25 l.stripe_unit = ceph_file_layout_su(ci->i_layout);
26 l.stripe_count = ceph_file_layout_stripe_count(ci->i_layout);
27 l.object_size = ceph_file_layout_object_size(ci->i_layout);
28 l.data_pool = le32_to_cpu(ci->i_layout.fl_pg_pool);
29 l.preferred_osd = (s32)-1;
30 if (copy_to_user(arg, &l, sizeof(l)))
31 return -EFAULT;
32 }
33
34 return err;
35 }
36
37 static long ceph_ioctl_set_layout(struct file *file, void __user *arg)
38 {
39 struct inode *inode = file->f_dentry->d_inode;
40 struct inode *parent_inode;
41 struct ceph_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc;
42 struct ceph_mds_request *req;
43 struct ceph_ioctl_layout l;
44 struct ceph_inode_info *ci = ceph_inode(file->f_dentry->d_inode);
45 struct ceph_ioctl_layout nl;
46 int err, i;
47
48 if (copy_from_user(&l, arg, sizeof(l)))
49 return -EFAULT;
50
51 /* preferred_osd is no longer supported */
52 if (l.preferred_osd != -1)
53 return -EINVAL;
54
55 /* validate changed params against current layout */
56 err = ceph_do_getattr(file->f_dentry->d_inode, CEPH_STAT_CAP_LAYOUT);
57 if (!err) {
58 nl.stripe_unit = ceph_file_layout_su(ci->i_layout);
59 nl.stripe_count = ceph_file_layout_stripe_count(ci->i_layout);
60 nl.object_size = ceph_file_layout_object_size(ci->i_layout);
61 nl.data_pool = le32_to_cpu(ci->i_layout.fl_pg_pool);
62 } else
63 return err;
64
65 if (l.stripe_count)
66 nl.stripe_count = l.stripe_count;
67 if (l.stripe_unit)
68 nl.stripe_unit = l.stripe_unit;
69 if (l.object_size)
70 nl.object_size = l.object_size;
71 if (l.data_pool)
72 nl.data_pool = l.data_pool;
73
74 if ((nl.object_size & ~PAGE_MASK) ||
75 (nl.stripe_unit & ~PAGE_MASK) ||
76 ((unsigned)nl.object_size % (unsigned)nl.stripe_unit))
77 return -EINVAL;
78
79 /* make sure it's a valid data pool */
80 if (l.data_pool > 0) {
81 mutex_lock(&mdsc->mutex);
82 err = -EINVAL;
83 for (i = 0; i < mdsc->mdsmap->m_num_data_pg_pools; i++)
84 if (mdsc->mdsmap->m_data_pg_pools[i] == l.data_pool) {
85 err = 0;
86 break;
87 }
88 mutex_unlock(&mdsc->mutex);
89 if (err)
90 return err;
91 }
92
93 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SETLAYOUT,
94 USE_AUTH_MDS);
95 if (IS_ERR(req))
96 return PTR_ERR(req);
97 req->r_inode = inode;
98 ihold(inode);
99 req->r_inode_drop = CEPH_CAP_FILE_SHARED | CEPH_CAP_FILE_EXCL;
100
101 req->r_args.setlayout.layout.fl_stripe_unit =
102 cpu_to_le32(l.stripe_unit);
103 req->r_args.setlayout.layout.fl_stripe_count =
104 cpu_to_le32(l.stripe_count);
105 req->r_args.setlayout.layout.fl_object_size =
106 cpu_to_le32(l.object_size);
107 req->r_args.setlayout.layout.fl_pg_pool = cpu_to_le32(l.data_pool);
108
109 parent_inode = ceph_get_dentry_parent_inode(file->f_dentry);
110 err = ceph_mdsc_do_request(mdsc, parent_inode, req);
111 iput(parent_inode);
112 ceph_mdsc_put_request(req);
113 return err;
114 }
115
116 /*
117 * Set a layout policy on a directory inode. All items in the tree
118 * rooted at this inode will inherit this layout on creation,
119 * (It doesn't apply retroactively )
120 * unless a subdirectory has its own layout policy.
121 */
122 static long ceph_ioctl_set_layout_policy (struct file *file, void __user *arg)
123 {
124 struct inode *inode = file->f_dentry->d_inode;
125 struct ceph_mds_request *req;
126 struct ceph_ioctl_layout l;
127 int err, i;
128 struct ceph_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc;
129
130 /* copy and validate */
131 if (copy_from_user(&l, arg, sizeof(l)))
132 return -EFAULT;
133
134 if ((l.object_size & ~PAGE_MASK) ||
135 (l.stripe_unit & ~PAGE_MASK) ||
136 !l.stripe_unit ||
137 (l.object_size &&
138 (unsigned)l.object_size % (unsigned)l.stripe_unit))
139 return -EINVAL;
140
141 /* make sure it's a valid data pool */
142 if (l.data_pool > 0) {
143 mutex_lock(&mdsc->mutex);
144 err = -EINVAL;
145 for (i = 0; i < mdsc->mdsmap->m_num_data_pg_pools; i++)
146 if (mdsc->mdsmap->m_data_pg_pools[i] == l.data_pool) {
147 err = 0;
148 break;
149 }
150 mutex_unlock(&mdsc->mutex);
151 if (err)
152 return err;
153 }
154
155 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SETDIRLAYOUT,
156 USE_AUTH_MDS);
157
158 if (IS_ERR(req))
159 return PTR_ERR(req);
160 req->r_inode = inode;
161 ihold(inode);
162
163 req->r_args.setlayout.layout.fl_stripe_unit =
164 cpu_to_le32(l.stripe_unit);
165 req->r_args.setlayout.layout.fl_stripe_count =
166 cpu_to_le32(l.stripe_count);
167 req->r_args.setlayout.layout.fl_object_size =
168 cpu_to_le32(l.object_size);
169 req->r_args.setlayout.layout.fl_pg_pool =
170 cpu_to_le32(l.data_pool);
171
172 err = ceph_mdsc_do_request(mdsc, inode, req);
173 ceph_mdsc_put_request(req);
174 return err;
175 }
176
177 /*
178 * Return object name, size/offset information, and location (OSD
179 * number, network address) for a given file offset.
180 */
181 static long ceph_ioctl_get_dataloc(struct file *file, void __user *arg)
182 {
183 struct ceph_ioctl_dataloc dl;
184 struct inode *inode = file->f_dentry->d_inode;
185 struct ceph_inode_info *ci = ceph_inode(inode);
186 struct ceph_osd_client *osdc =
187 &ceph_sb_to_client(inode->i_sb)->client->osdc;
188 u64 len = 1, olen;
189 u64 tmp;
190 struct ceph_object_layout ol;
191 struct ceph_pg pgid;
192
193 /* copy and validate */
194 if (copy_from_user(&dl, arg, sizeof(dl)))
195 return -EFAULT;
196
197 down_read(&osdc->map_sem);
198 ceph_calc_file_object_mapping(&ci->i_layout, dl.file_offset, &len,
199 &dl.object_no, &dl.object_offset, &olen);
200 dl.file_offset -= dl.object_offset;
201 dl.object_size = ceph_file_layout_object_size(ci->i_layout);
202 dl.block_size = ceph_file_layout_su(ci->i_layout);
203
204 /* block_offset = object_offset % block_size */
205 tmp = dl.object_offset;
206 dl.block_offset = do_div(tmp, dl.block_size);
207
208 snprintf(dl.object_name, sizeof(dl.object_name), "%llx.%08llx",
209 ceph_ino(inode), dl.object_no);
210 ceph_calc_object_layout(&ol, dl.object_name, &ci->i_layout,
211 osdc->osdmap);
212
213 pgid = ol.ol_pgid;
214 dl.osd = ceph_calc_pg_primary(osdc->osdmap, pgid);
215 if (dl.osd >= 0) {
216 struct ceph_entity_addr *a =
217 ceph_osd_addr(osdc->osdmap, dl.osd);
218 if (a)
219 memcpy(&dl.osd_addr, &a->in_addr, sizeof(dl.osd_addr));
220 } else {
221 memset(&dl.osd_addr, 0, sizeof(dl.osd_addr));
222 }
223 up_read(&osdc->map_sem);
224
225 /* send result back to user */
226 if (copy_to_user(arg, &dl, sizeof(dl)))
227 return -EFAULT;
228
229 return 0;
230 }
231
232 static long ceph_ioctl_lazyio(struct file *file)
233 {
234 struct ceph_file_info *fi = file->private_data;
235 struct inode *inode = file->f_dentry->d_inode;
236 struct ceph_inode_info *ci = ceph_inode(inode);
237
238 if ((fi->fmode & CEPH_FILE_MODE_LAZY) == 0) {
239 spin_lock(&ci->i_ceph_lock);
240 ci->i_nr_by_mode[fi->fmode]--;
241 fi->fmode |= CEPH_FILE_MODE_LAZY;
242 ci->i_nr_by_mode[fi->fmode]++;
243 spin_unlock(&ci->i_ceph_lock);
244 dout("ioctl_layzio: file %p marked lazy\n", file);
245
246 ceph_check_caps(ci, 0, NULL);
247 } else {
248 dout("ioctl_layzio: file %p already lazy\n", file);
249 }
250 return 0;
251 }
252
253 static long ceph_ioctl_syncio(struct file *file)
254 {
255 struct ceph_file_info *fi = file->private_data;
256
257 fi->flags |= CEPH_F_SYNC;
258 return 0;
259 }
260
261 long ceph_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
262 {
263 dout("ioctl file %p cmd %u arg %lu\n", file, cmd, arg);
264 switch (cmd) {
265 case CEPH_IOC_GET_LAYOUT:
266 return ceph_ioctl_get_layout(file, (void __user *)arg);
267
268 case CEPH_IOC_SET_LAYOUT:
269 return ceph_ioctl_set_layout(file, (void __user *)arg);
270
271 case CEPH_IOC_SET_LAYOUT_POLICY:
272 return ceph_ioctl_set_layout_policy(file, (void __user *)arg);
273
274 case CEPH_IOC_GET_DATALOC:
275 return ceph_ioctl_get_dataloc(file, (void __user *)arg);
276
277 case CEPH_IOC_LAZYIO:
278 return ceph_ioctl_lazyio(file);
279
280 case CEPH_IOC_SYNCIO:
281 return ceph_ioctl_syncio(file);
282 }
283
284 return -ENOTTY;
285 }