diff options
author | Sage Weil <sage@inktank.com> | 2012-05-07 18:34:35 -0400 |
---|---|---|
committer | Sage Weil <sage@inktank.com> | 2012-05-07 18:34:35 -0400 |
commit | e49bf4c51cbe27439c00516d4297193d45dd4097 (patch) | |
tree | 5be5727f0828f74719e7f0783fb1fba829658b47 | |
parent | 3469ac1aa3a2f1e2586a412923c414779a0af854 (diff) |
ceph: refactor SETLAYOUT and SETDIRLAYOUT ioctl checks into common helper
Both of these methods perform similar checks; move that code to a helper
so that we can ensure the checks are consistent.
Reviewed-by: Alex Elder <elder@inktank.com>
Signed-off-by: Sage Weil <sage@inktank.com>
-rw-r--r-- | fs/ceph/ioctl.c | 82 |
1 files changed, 38 insertions, 44 deletions
diff --git a/fs/ceph/ioctl.c b/fs/ceph/ioctl.c index 4feab52c5bff..0e2f021109ee 100644 --- a/fs/ceph/ioctl.c +++ b/fs/ceph/ioctl.c | |||
@@ -34,6 +34,36 @@ static long ceph_ioctl_get_layout(struct file *file, void __user *arg) | |||
34 | return err; | 34 | return err; |
35 | } | 35 | } |
36 | 36 | ||
37 | static long __validate_layout(struct ceph_mds_client *mdsc, | ||
38 | struct ceph_ioctl_layout *l) | ||
39 | { | ||
40 | int i, err; | ||
41 | |||
42 | /* preferred_osd is no longer supported */ | ||
43 | if (l->preferred_osd != -1) | ||
44 | return -EINVAL; | ||
45 | |||
46 | /* validate striping parameters */ | ||
47 | if ((l->object_size & ~PAGE_MASK) || | ||
48 | (l->stripe_unit & ~PAGE_MASK) || | ||
49 | ((unsigned)l->object_size % (unsigned)l->stripe_unit)) | ||
50 | return -EINVAL; | ||
51 | |||
52 | /* make sure it's a valid data pool */ | ||
53 | mutex_lock(&mdsc->mutex); | ||
54 | err = -EINVAL; | ||
55 | for (i = 0; i < mdsc->mdsmap->m_num_data_pg_pools; i++) | ||
56 | if (mdsc->mdsmap->m_data_pg_pools[i] == l->data_pool) { | ||
57 | err = 0; | ||
58 | break; | ||
59 | } | ||
60 | mutex_unlock(&mdsc->mutex); | ||
61 | if (err) | ||
62 | return err; | ||
63 | |||
64 | return 0; | ||
65 | } | ||
66 | |||
37 | static long ceph_ioctl_set_layout(struct file *file, void __user *arg) | 67 | static long ceph_ioctl_set_layout(struct file *file, void __user *arg) |
38 | { | 68 | { |
39 | struct inode *inode = file->f_dentry->d_inode; | 69 | struct inode *inode = file->f_dentry->d_inode; |
@@ -43,15 +73,11 @@ static long ceph_ioctl_set_layout(struct file *file, void __user *arg) | |||
43 | struct ceph_ioctl_layout l; | 73 | struct ceph_ioctl_layout l; |
44 | struct ceph_inode_info *ci = ceph_inode(file->f_dentry->d_inode); | 74 | struct ceph_inode_info *ci = ceph_inode(file->f_dentry->d_inode); |
45 | struct ceph_ioctl_layout nl; | 75 | struct ceph_ioctl_layout nl; |
46 | int err, i; | 76 | int err; |
47 | 77 | ||
48 | if (copy_from_user(&l, arg, sizeof(l))) | 78 | if (copy_from_user(&l, arg, sizeof(l))) |
49 | return -EFAULT; | 79 | return -EFAULT; |
50 | 80 | ||
51 | /* preferred_osd is no longer supported */ | ||
52 | if (l.preferred_osd != -1) | ||
53 | return -EINVAL; | ||
54 | |||
55 | /* validate changed params against current layout */ | 81 | /* validate changed params against current layout */ |
56 | err = ceph_do_getattr(file->f_dentry->d_inode, CEPH_STAT_CAP_LAYOUT); | 82 | err = ceph_do_getattr(file->f_dentry->d_inode, CEPH_STAT_CAP_LAYOUT); |
57 | if (!err) { | 83 | if (!err) { |
@@ -71,24 +97,9 @@ static long ceph_ioctl_set_layout(struct file *file, void __user *arg) | |||
71 | if (l.data_pool) | 97 | if (l.data_pool) |
72 | nl.data_pool = l.data_pool; | 98 | nl.data_pool = l.data_pool; |
73 | 99 | ||
74 | if ((nl.object_size & ~PAGE_MASK) || | 100 | err = __validate_layout(mdsc, &nl); |
75 | (nl.stripe_unit & ~PAGE_MASK) || | 101 | if (err) |
76 | ((unsigned)nl.object_size % (unsigned)nl.stripe_unit)) | 102 | return err; |
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 | 103 | ||
93 | req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SETLAYOUT, | 104 | req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SETLAYOUT, |
94 | USE_AUTH_MDS); | 105 | USE_AUTH_MDS); |
@@ -124,33 +135,16 @@ static long ceph_ioctl_set_layout_policy (struct file *file, void __user *arg) | |||
124 | struct inode *inode = file->f_dentry->d_inode; | 135 | struct inode *inode = file->f_dentry->d_inode; |
125 | struct ceph_mds_request *req; | 136 | struct ceph_mds_request *req; |
126 | struct ceph_ioctl_layout l; | 137 | struct ceph_ioctl_layout l; |
127 | int err, i; | 138 | int err; |
128 | struct ceph_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc; | 139 | struct ceph_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc; |
129 | 140 | ||
130 | /* copy and validate */ | 141 | /* copy and validate */ |
131 | if (copy_from_user(&l, arg, sizeof(l))) | 142 | if (copy_from_user(&l, arg, sizeof(l))) |
132 | return -EFAULT; | 143 | return -EFAULT; |
133 | 144 | ||
134 | if ((l.object_size & ~PAGE_MASK) || | 145 | err = __validate_layout(mdsc, &l); |
135 | (l.stripe_unit & ~PAGE_MASK) || | 146 | if (err) |
136 | !l.stripe_unit || | 147 | return err; |
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 | 148 | ||
155 | req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SETDIRLAYOUT, | 149 | req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SETDIRLAYOUT, |
156 | USE_AUTH_MDS); | 150 | USE_AUTH_MDS); |