4 #include "mds_client.h"
5 #include <linux/ceph/ceph_debug.h>
15 * get and set the file layout
17 static long ceph_ioctl_get_layout(struct file *file, void __user *arg)
19 struct ceph_inode_info *ci = ceph_inode(file->f_dentry->d_inode);
20 struct ceph_ioctl_layout l;
23 err = ceph_do_getattr(file->f_dentry->d_inode, CEPH_STAT_CAP_LAYOUT);
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)))
37 static long ceph_ioctl_set_layout(struct file *file, void __user *arg)
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;
48 if (copy_from_user(&l, arg, sizeof(l)))
51 /* preferred_osd is no longer supported */
52 if (l.preferred_osd != -1)
55 /* validate changed params against current layout */
56 err = ceph_do_getattr(file->f_dentry->d_inode, CEPH_STAT_CAP_LAYOUT);
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);
66 nl.stripe_count = l.stripe_count;
68 nl.stripe_unit = l.stripe_unit;
70 nl.object_size = l.object_size;
72 nl.data_pool = l.data_pool;
74 if ((nl.object_size & ~PAGE_MASK) ||
75 (nl.stripe_unit & ~PAGE_MASK) ||
76 ((unsigned)nl.object_size % (unsigned)nl.stripe_unit))
79 /* make sure it's a valid data pool */
80 if (l.data_pool > 0) {
81 mutex_lock(&mdsc->mutex);
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) {
88 mutex_unlock(&mdsc->mutex);
93 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SETLAYOUT,
99 req->r_inode_drop = CEPH_CAP_FILE_SHARED | CEPH_CAP_FILE_EXCL;
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);
109 parent_inode = ceph_get_dentry_parent_inode(file->f_dentry);
110 err = ceph_mdsc_do_request(mdsc, parent_inode, req);
112 ceph_mdsc_put_request(req);
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.
122 static long ceph_ioctl_set_layout_policy (struct file *file, void __user *arg)
124 struct inode *inode = file->f_dentry->d_inode;
125 struct ceph_mds_request *req;
126 struct ceph_ioctl_layout l;
128 struct ceph_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc;
130 /* copy and validate */
131 if (copy_from_user(&l, arg, sizeof(l)))
134 if ((l.object_size & ~PAGE_MASK) ||
135 (l.stripe_unit & ~PAGE_MASK) ||
138 (unsigned)l.object_size % (unsigned)l.stripe_unit))
141 /* make sure it's a valid data pool */
142 if (l.data_pool > 0) {
143 mutex_lock(&mdsc->mutex);
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) {
150 mutex_unlock(&mdsc->mutex);
155 req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SETDIRLAYOUT,
160 req->r_inode = inode;
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);
172 err = ceph_mdsc_do_request(mdsc, inode, req);
173 ceph_mdsc_put_request(req);
178 * Return object name, size/offset information, and location (OSD
179 * number, network address) for a given file offset.
181 static long ceph_ioctl_get_dataloc(struct file *file, void __user *arg)
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;
190 struct ceph_object_layout ol;
193 /* copy and validate */
194 if (copy_from_user(&dl, arg, sizeof(dl)))
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);
204 /* block_offset = object_offset % block_size */
205 tmp = dl.object_offset;
206 dl.block_offset = do_div(tmp, dl.block_size);
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,
214 dl.osd = ceph_calc_pg_primary(osdc->osdmap, pgid);
216 struct ceph_entity_addr *a =
217 ceph_osd_addr(osdc->osdmap, dl.osd);
219 memcpy(&dl.osd_addr, &a->in_addr, sizeof(dl.osd_addr));
221 memset(&dl.osd_addr, 0, sizeof(dl.osd_addr));
223 up_read(&osdc->map_sem);
225 /* send result back to user */
226 if (copy_to_user(arg, &dl, sizeof(dl)))
232 static long ceph_ioctl_lazyio(struct file *file)
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);
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);
246 ceph_check_caps(ci, 0, NULL);
248 dout("ioctl_layzio: file %p already lazy\n", file);
253 static long ceph_ioctl_syncio(struct file *file)
255 struct ceph_file_info *fi = file->private_data;
257 fi->flags |= CEPH_F_SYNC;
261 long ceph_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
263 dout("ioctl file %p cmd %u arg %lu\n", file, cmd, arg);
265 case CEPH_IOC_GET_LAYOUT:
266 return ceph_ioctl_get_layout(file, (void __user *)arg);
268 case CEPH_IOC_SET_LAYOUT:
269 return ceph_ioctl_set_layout(file, (void __user *)arg);
271 case CEPH_IOC_SET_LAYOUT_POLICY:
272 return ceph_ioctl_set_layout_policy(file, (void __user *)arg);
274 case CEPH_IOC_GET_DATALOC:
275 return ceph_ioctl_get_dataloc(file, (void __user *)arg);
277 case CEPH_IOC_LAZYIO:
278 return ceph_ioctl_lazyio(file);
280 case CEPH_IOC_SYNCIO:
281 return ceph_ioctl_syncio(file);