Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1 | |
| 2 | #include "ceph_debug.h" |
| 3 | |
| 4 | #include <linux/backing-dev.h> |
| 5 | #include <linux/fs.h> |
| 6 | #include <linux/inet.h> |
| 7 | #include <linux/in6.h> |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/mount.h> |
| 10 | #include <linux/parser.h> |
| 11 | #include <linux/rwsem.h> |
| 12 | #include <linux/sched.h> |
| 13 | #include <linux/seq_file.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 14 | #include <linux/slab.h> |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 15 | #include <linux/statfs.h> |
| 16 | #include <linux/string.h> |
| 17 | #include <linux/version.h> |
| 18 | #include <linux/vmalloc.h> |
| 19 | |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 20 | #include "decode.h" |
| 21 | #include "super.h" |
| 22 | #include "mon_client.h" |
Sage Weil | 0743304 | 2009-11-18 16:50:41 -0800 | [diff] [blame] | 23 | #include "auth.h" |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 24 | |
| 25 | /* |
| 26 | * Ceph superblock operations |
| 27 | * |
| 28 | * Handle the basics of mounting, unmounting. |
| 29 | */ |
| 30 | |
| 31 | |
| 32 | /* |
| 33 | * find filename portion of a path (/foo/bar/baz -> baz) |
| 34 | */ |
| 35 | const char *ceph_file_part(const char *s, int len) |
| 36 | { |
| 37 | const char *e = s + len; |
| 38 | |
| 39 | while (e != s && *(e-1) != '/') |
| 40 | e--; |
| 41 | return e; |
| 42 | } |
| 43 | |
| 44 | |
| 45 | /* |
| 46 | * super ops |
| 47 | */ |
| 48 | static void ceph_put_super(struct super_block *s) |
| 49 | { |
Sage Weil | 5dfc589 | 2010-05-04 16:14:46 -0700 | [diff] [blame] | 50 | struct ceph_client *client = ceph_sb_to_client(s); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 51 | |
| 52 | dout("put_super\n"); |
Sage Weil | 5dfc589 | 2010-05-04 16:14:46 -0700 | [diff] [blame] | 53 | ceph_mdsc_close_sessions(&client->mdsc); |
| 54 | |
| 55 | /* |
| 56 | * ensure we release the bdi before put_anon_super releases |
| 57 | * the device name. |
| 58 | */ |
| 59 | if (s->s_bdi == &client->backing_dev_info) { |
| 60 | bdi_unregister(&client->backing_dev_info); |
| 61 | s->s_bdi = NULL; |
| 62 | } |
| 63 | |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 64 | return; |
| 65 | } |
| 66 | |
| 67 | static int ceph_statfs(struct dentry *dentry, struct kstatfs *buf) |
| 68 | { |
| 69 | struct ceph_client *client = ceph_inode_to_client(dentry->d_inode); |
| 70 | struct ceph_monmap *monmap = client->monc.monmap; |
| 71 | struct ceph_statfs st; |
| 72 | u64 fsid; |
| 73 | int err; |
| 74 | |
| 75 | dout("statfs\n"); |
| 76 | err = ceph_monc_do_statfs(&client->monc, &st); |
| 77 | if (err < 0) |
| 78 | return err; |
| 79 | |
| 80 | /* fill in kstatfs */ |
| 81 | buf->f_type = CEPH_SUPER_MAGIC; /* ?? */ |
| 82 | |
| 83 | /* |
| 84 | * express utilization in terms of large blocks to avoid |
| 85 | * overflow on 32-bit machines. |
| 86 | */ |
| 87 | buf->f_bsize = 1 << CEPH_BLOCK_SHIFT; |
| 88 | buf->f_blocks = le64_to_cpu(st.kb) >> (CEPH_BLOCK_SHIFT-10); |
| 89 | buf->f_bfree = (le64_to_cpu(st.kb) - le64_to_cpu(st.kb_used)) >> |
| 90 | (CEPH_BLOCK_SHIFT-10); |
| 91 | buf->f_bavail = le64_to_cpu(st.kb_avail) >> (CEPH_BLOCK_SHIFT-10); |
| 92 | |
| 93 | buf->f_files = le64_to_cpu(st.num_objects); |
| 94 | buf->f_ffree = -1; |
| 95 | buf->f_namelen = PATH_MAX; |
| 96 | buf->f_frsize = PAGE_CACHE_SIZE; |
| 97 | |
| 98 | /* leave fsid little-endian, regardless of host endianness */ |
| 99 | fsid = *(u64 *)(&monmap->fsid) ^ *((u64 *)&monmap->fsid + 1); |
| 100 | buf->f_fsid.val[0] = fsid & 0xffffffff; |
| 101 | buf->f_fsid.val[1] = fsid >> 32; |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
| 106 | |
| 107 | static int ceph_syncfs(struct super_block *sb, int wait) |
| 108 | { |
| 109 | dout("sync_fs %d\n", wait); |
Cheng Renquan | 640ef79 | 2010-03-26 17:40:33 +0800 | [diff] [blame] | 110 | ceph_osdc_sync(&ceph_sb_to_client(sb)->osdc); |
| 111 | ceph_mdsc_sync(&ceph_sb_to_client(sb)->mdsc); |
Sage Weil | f2cf418 | 2009-10-14 14:09:07 -0700 | [diff] [blame] | 112 | dout("sync_fs %d done\n", wait); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | |
| 117 | /** |
| 118 | * ceph_show_options - Show mount options in /proc/mounts |
| 119 | * @m: seq_file to write to |
| 120 | * @mnt: mount descriptor |
| 121 | */ |
| 122 | static int ceph_show_options(struct seq_file *m, struct vfsmount *mnt) |
| 123 | { |
| 124 | struct ceph_client *client = ceph_sb_to_client(mnt->mnt_sb); |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 125 | struct ceph_mount_args *args = client->mount_args; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 126 | |
| 127 | if (args->flags & CEPH_OPT_FSID) |
| 128 | seq_printf(m, ",fsidmajor=%llu,fsidminor%llu", |
| 129 | le64_to_cpu(*(__le64 *)&args->fsid.fsid[0]), |
| 130 | le64_to_cpu(*(__le64 *)&args->fsid.fsid[8])); |
| 131 | if (args->flags & CEPH_OPT_NOSHARE) |
| 132 | seq_puts(m, ",noshare"); |
| 133 | if (args->flags & CEPH_OPT_DIRSTAT) |
| 134 | seq_puts(m, ",dirstat"); |
| 135 | if ((args->flags & CEPH_OPT_RBYTES) == 0) |
| 136 | seq_puts(m, ",norbytes"); |
| 137 | if (args->flags & CEPH_OPT_NOCRC) |
| 138 | seq_puts(m, ",nocrc"); |
| 139 | if (args->flags & CEPH_OPT_NOASYNCREADDIR) |
| 140 | seq_puts(m, ",noasyncreaddir"); |
| 141 | if (strcmp(args->snapdir_name, CEPH_SNAPDIRNAME_DEFAULT)) |
| 142 | seq_printf(m, ",snapdirname=%s", args->snapdir_name); |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 143 | if (args->name) |
| 144 | seq_printf(m, ",name=%s", args->name); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 145 | if (args->secret) |
| 146 | seq_puts(m, ",secret=<hidden>"); |
| 147 | return 0; |
| 148 | } |
| 149 | |
| 150 | /* |
| 151 | * caches |
| 152 | */ |
| 153 | struct kmem_cache *ceph_inode_cachep; |
| 154 | struct kmem_cache *ceph_cap_cachep; |
| 155 | struct kmem_cache *ceph_dentry_cachep; |
| 156 | struct kmem_cache *ceph_file_cachep; |
| 157 | |
| 158 | static void ceph_inode_init_once(void *foo) |
| 159 | { |
| 160 | struct ceph_inode_info *ci = foo; |
| 161 | inode_init_once(&ci->vfs_inode); |
| 162 | } |
| 163 | |
Yehuda Sadeh | 2baba25 | 2009-12-18 13:51:57 -0800 | [diff] [blame] | 164 | static int default_congestion_kb(void) |
| 165 | { |
| 166 | int congestion_kb; |
| 167 | |
| 168 | /* |
| 169 | * Copied from NFS |
| 170 | * |
| 171 | * congestion size, scale with available memory. |
| 172 | * |
| 173 | * 64MB: 8192k |
| 174 | * 128MB: 11585k |
| 175 | * 256MB: 16384k |
| 176 | * 512MB: 23170k |
| 177 | * 1GB: 32768k |
| 178 | * 2GB: 46340k |
| 179 | * 4GB: 65536k |
| 180 | * 8GB: 92681k |
| 181 | * 16GB: 131072k |
| 182 | * |
| 183 | * This allows larger machines to have larger/more transfers. |
| 184 | * Limit the default to 256M |
| 185 | */ |
| 186 | congestion_kb = (16*int_sqrt(totalram_pages)) << (PAGE_SHIFT-10); |
| 187 | if (congestion_kb > 256*1024) |
| 188 | congestion_kb = 256*1024; |
| 189 | |
| 190 | return congestion_kb; |
| 191 | } |
| 192 | |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 193 | static int __init init_caches(void) |
| 194 | { |
| 195 | ceph_inode_cachep = kmem_cache_create("ceph_inode_info", |
| 196 | sizeof(struct ceph_inode_info), |
| 197 | __alignof__(struct ceph_inode_info), |
| 198 | (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD), |
| 199 | ceph_inode_init_once); |
| 200 | if (ceph_inode_cachep == NULL) |
| 201 | return -ENOMEM; |
| 202 | |
| 203 | ceph_cap_cachep = KMEM_CACHE(ceph_cap, |
| 204 | SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD); |
| 205 | if (ceph_cap_cachep == NULL) |
| 206 | goto bad_cap; |
| 207 | |
| 208 | ceph_dentry_cachep = KMEM_CACHE(ceph_dentry_info, |
| 209 | SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD); |
| 210 | if (ceph_dentry_cachep == NULL) |
| 211 | goto bad_dentry; |
| 212 | |
| 213 | ceph_file_cachep = KMEM_CACHE(ceph_file_info, |
| 214 | SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD); |
| 215 | if (ceph_file_cachep == NULL) |
| 216 | goto bad_file; |
| 217 | |
| 218 | return 0; |
| 219 | |
| 220 | bad_file: |
| 221 | kmem_cache_destroy(ceph_dentry_cachep); |
| 222 | bad_dentry: |
| 223 | kmem_cache_destroy(ceph_cap_cachep); |
| 224 | bad_cap: |
| 225 | kmem_cache_destroy(ceph_inode_cachep); |
| 226 | return -ENOMEM; |
| 227 | } |
| 228 | |
| 229 | static void destroy_caches(void) |
| 230 | { |
| 231 | kmem_cache_destroy(ceph_inode_cachep); |
| 232 | kmem_cache_destroy(ceph_cap_cachep); |
| 233 | kmem_cache_destroy(ceph_dentry_cachep); |
| 234 | kmem_cache_destroy(ceph_file_cachep); |
| 235 | } |
| 236 | |
| 237 | |
| 238 | /* |
| 239 | * ceph_umount_begin - initiate forced umount. Tear down down the |
| 240 | * mount, skipping steps that may hang while waiting for server(s). |
| 241 | */ |
| 242 | static void ceph_umount_begin(struct super_block *sb) |
| 243 | { |
| 244 | struct ceph_client *client = ceph_sb_to_client(sb); |
| 245 | |
| 246 | dout("ceph_umount_begin - starting forced umount\n"); |
| 247 | if (!client) |
| 248 | return; |
| 249 | client->mount_state = CEPH_MOUNT_SHUTDOWN; |
| 250 | return; |
| 251 | } |
| 252 | |
| 253 | static const struct super_operations ceph_super_ops = { |
| 254 | .alloc_inode = ceph_alloc_inode, |
| 255 | .destroy_inode = ceph_destroy_inode, |
| 256 | .write_inode = ceph_write_inode, |
| 257 | .sync_fs = ceph_syncfs, |
| 258 | .put_super = ceph_put_super, |
| 259 | .show_options = ceph_show_options, |
| 260 | .statfs = ceph_statfs, |
| 261 | .umount_begin = ceph_umount_begin, |
| 262 | }; |
| 263 | |
| 264 | |
| 265 | const char *ceph_msg_type_name(int type) |
| 266 | { |
| 267 | switch (type) { |
| 268 | case CEPH_MSG_SHUTDOWN: return "shutdown"; |
| 269 | case CEPH_MSG_PING: return "ping"; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 270 | case CEPH_MSG_AUTH: return "auth"; |
| 271 | case CEPH_MSG_AUTH_REPLY: return "auth_reply"; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 272 | case CEPH_MSG_MON_MAP: return "mon_map"; |
| 273 | case CEPH_MSG_MON_GET_MAP: return "mon_get_map"; |
| 274 | case CEPH_MSG_MON_SUBSCRIBE: return "mon_subscribe"; |
| 275 | case CEPH_MSG_MON_SUBSCRIBE_ACK: return "mon_subscribe_ack"; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 276 | case CEPH_MSG_STATFS: return "statfs"; |
| 277 | case CEPH_MSG_STATFS_REPLY: return "statfs_reply"; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 278 | case CEPH_MSG_MDS_MAP: return "mds_map"; |
| 279 | case CEPH_MSG_CLIENT_SESSION: return "client_session"; |
| 280 | case CEPH_MSG_CLIENT_RECONNECT: return "client_reconnect"; |
| 281 | case CEPH_MSG_CLIENT_REQUEST: return "client_request"; |
| 282 | case CEPH_MSG_CLIENT_REQUEST_FORWARD: return "client_request_forward"; |
| 283 | case CEPH_MSG_CLIENT_REPLY: return "client_reply"; |
| 284 | case CEPH_MSG_CLIENT_CAPS: return "client_caps"; |
| 285 | case CEPH_MSG_CLIENT_CAPRELEASE: return "client_cap_release"; |
| 286 | case CEPH_MSG_CLIENT_SNAP: return "client_snap"; |
| 287 | case CEPH_MSG_CLIENT_LEASE: return "client_lease"; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 288 | case CEPH_MSG_OSD_MAP: return "osd_map"; |
| 289 | case CEPH_MSG_OSD_OP: return "osd_op"; |
| 290 | case CEPH_MSG_OSD_OPREPLY: return "osd_opreply"; |
| 291 | default: return "unknown"; |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | |
| 296 | /* |
| 297 | * mount options |
| 298 | */ |
| 299 | enum { |
| 300 | Opt_fsidmajor, |
| 301 | Opt_fsidminor, |
| 302 | Opt_monport, |
| 303 | Opt_wsize, |
| 304 | Opt_rsize, |
| 305 | Opt_osdtimeout, |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 306 | Opt_osdkeepalivetimeout, |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 307 | Opt_mount_timeout, |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 308 | Opt_osd_idle_ttl, |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 309 | Opt_caps_wanted_delay_min, |
| 310 | Opt_caps_wanted_delay_max, |
| 311 | Opt_readdir_max_entries, |
Yehuda Sadeh | 2baba25 | 2009-12-18 13:51:57 -0800 | [diff] [blame] | 312 | Opt_congestion_kb, |
Sage Weil | e53c2fe | 2009-10-27 10:19:28 -0700 | [diff] [blame] | 313 | Opt_last_int, |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 314 | /* int args above */ |
| 315 | Opt_snapdirname, |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 316 | Opt_name, |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 317 | Opt_secret, |
Sage Weil | e53c2fe | 2009-10-27 10:19:28 -0700 | [diff] [blame] | 318 | Opt_last_string, |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 319 | /* string args above */ |
| 320 | Opt_ip, |
| 321 | Opt_noshare, |
| 322 | Opt_dirstat, |
| 323 | Opt_nodirstat, |
| 324 | Opt_rbytes, |
| 325 | Opt_norbytes, |
| 326 | Opt_nocrc, |
| 327 | Opt_noasyncreaddir, |
| 328 | }; |
| 329 | |
| 330 | static match_table_t arg_tokens = { |
| 331 | {Opt_fsidmajor, "fsidmajor=%ld"}, |
| 332 | {Opt_fsidminor, "fsidminor=%ld"}, |
| 333 | {Opt_monport, "monport=%d"}, |
| 334 | {Opt_wsize, "wsize=%d"}, |
| 335 | {Opt_rsize, "rsize=%d"}, |
| 336 | {Opt_osdtimeout, "osdtimeout=%d"}, |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 337 | {Opt_osdkeepalivetimeout, "osdkeepalive=%d"}, |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 338 | {Opt_mount_timeout, "mount_timeout=%d"}, |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 339 | {Opt_osd_idle_ttl, "osd_idle_ttl=%d"}, |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 340 | {Opt_caps_wanted_delay_min, "caps_wanted_delay_min=%d"}, |
| 341 | {Opt_caps_wanted_delay_max, "caps_wanted_delay_max=%d"}, |
| 342 | {Opt_readdir_max_entries, "readdir_max_entries=%d"}, |
Yehuda Sadeh | 2baba25 | 2009-12-18 13:51:57 -0800 | [diff] [blame] | 343 | {Opt_congestion_kb, "write_congestion_kb=%d"}, |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 344 | /* int args above */ |
| 345 | {Opt_snapdirname, "snapdirname=%s"}, |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 346 | {Opt_name, "name=%s"}, |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 347 | {Opt_secret, "secret=%s"}, |
| 348 | /* string args above */ |
| 349 | {Opt_ip, "ip=%s"}, |
| 350 | {Opt_noshare, "noshare"}, |
| 351 | {Opt_dirstat, "dirstat"}, |
| 352 | {Opt_nodirstat, "nodirstat"}, |
| 353 | {Opt_rbytes, "rbytes"}, |
| 354 | {Opt_norbytes, "norbytes"}, |
| 355 | {Opt_nocrc, "nocrc"}, |
| 356 | {Opt_noasyncreaddir, "noasyncreaddir"}, |
| 357 | {-1, NULL} |
| 358 | }; |
| 359 | |
| 360 | |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 361 | static struct ceph_mount_args *parse_mount_args(int flags, char *options, |
| 362 | const char *dev_name, |
| 363 | const char **path) |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 364 | { |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 365 | struct ceph_mount_args *args; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 366 | const char *c; |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 367 | int err = -ENOMEM; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 368 | substring_t argstr[MAX_OPT_ARGS]; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 369 | |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 370 | args = kzalloc(sizeof(*args), GFP_KERNEL); |
| 371 | if (!args) |
| 372 | return ERR_PTR(-ENOMEM); |
| 373 | args->mon_addr = kcalloc(CEPH_MAX_MON, sizeof(*args->mon_addr), |
| 374 | GFP_KERNEL); |
| 375 | if (!args->mon_addr) |
| 376 | goto out; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 377 | |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 378 | dout("parse_mount_args %p, dev_name '%s'\n", args, dev_name); |
Sage Weil | 7b813c46 | 2009-10-26 22:07:53 -0700 | [diff] [blame] | 379 | |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 380 | /* start with defaults */ |
| 381 | args->sb_flags = flags; |
| 382 | args->flags = CEPH_OPT_DEFAULT; |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 383 | args->osd_timeout = CEPH_OSD_TIMEOUT_DEFAULT; |
| 384 | args->osd_keepalive_timeout = CEPH_OSD_KEEPALIVE_DEFAULT; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 385 | args->mount_timeout = CEPH_MOUNT_TIMEOUT_DEFAULT; /* seconds */ |
Yehuda Sadeh | f5a2041 | 2010-02-03 11:00:26 -0800 | [diff] [blame] | 386 | args->osd_idle_ttl = CEPH_OSD_IDLE_TTL_DEFAULT; /* seconds */ |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 387 | args->caps_wanted_delay_min = CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT; |
| 388 | args->caps_wanted_delay_max = CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT; |
Sage Weil | 8fa9765 | 2009-10-16 14:44:35 -0700 | [diff] [blame] | 389 | args->rsize = CEPH_MOUNT_RSIZE_DEFAULT; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 390 | args->snapdir_name = kstrdup(CEPH_SNAPDIRNAME_DEFAULT, GFP_KERNEL); |
| 391 | args->cap_release_safety = CEPH_CAPS_PER_RELEASE * 4; |
| 392 | args->max_readdir = 1024; |
Yehuda Sadeh | 2baba25 | 2009-12-18 13:51:57 -0800 | [diff] [blame] | 393 | args->congestion_kb = default_congestion_kb(); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 394 | |
| 395 | /* ip1[:port1][,ip2[:port2]...]:/subdir/in/fs */ |
Sage Weil | 7b813c46 | 2009-10-26 22:07:53 -0700 | [diff] [blame] | 396 | err = -EINVAL; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 397 | if (!dev_name) |
Sage Weil | 7b813c46 | 2009-10-26 22:07:53 -0700 | [diff] [blame] | 398 | goto out; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 399 | *path = strstr(dev_name, ":/"); |
| 400 | if (*path == NULL) { |
| 401 | pr_err("device name is missing path (no :/ in %s)\n", |
| 402 | dev_name); |
Sage Weil | 7b813c46 | 2009-10-26 22:07:53 -0700 | [diff] [blame] | 403 | goto out; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | /* get mon ip(s) */ |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 407 | err = ceph_parse_ips(dev_name, *path, args->mon_addr, |
| 408 | CEPH_MAX_MON, &args->num_mon); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 409 | if (err < 0) |
Sage Weil | 7b813c46 | 2009-10-26 22:07:53 -0700 | [diff] [blame] | 410 | goto out; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 411 | |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 412 | /* path on server */ |
| 413 | *path += 2; |
| 414 | dout("server path '%s'\n", *path); |
| 415 | |
| 416 | /* parse mount options */ |
| 417 | while ((c = strsep(&options, ",")) != NULL) { |
| 418 | int token, intval, ret; |
| 419 | if (!*c) |
| 420 | continue; |
Sage Weil | 7b813c46 | 2009-10-26 22:07:53 -0700 | [diff] [blame] | 421 | err = -EINVAL; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 422 | token = match_token((char *)c, arg_tokens, argstr); |
| 423 | if (token < 0) { |
| 424 | pr_err("bad mount option at '%s'\n", c); |
Sage Weil | 7b813c46 | 2009-10-26 22:07:53 -0700 | [diff] [blame] | 425 | goto out; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 426 | } |
Sage Weil | e53c2fe | 2009-10-27 10:19:28 -0700 | [diff] [blame] | 427 | if (token < Opt_last_int) { |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 428 | ret = match_int(&argstr[0], &intval); |
| 429 | if (ret < 0) { |
| 430 | pr_err("bad mount option arg (not int) " |
| 431 | "at '%s'\n", c); |
| 432 | continue; |
| 433 | } |
Sage Weil | e53c2fe | 2009-10-27 10:19:28 -0700 | [diff] [blame] | 434 | dout("got int token %d val %d\n", token, intval); |
| 435 | } else if (token > Opt_last_int && token < Opt_last_string) { |
| 436 | dout("got string token %d val %s\n", token, |
| 437 | argstr[0].from); |
| 438 | } else { |
| 439 | dout("got token %d\n", token); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 440 | } |
| 441 | switch (token) { |
| 442 | case Opt_fsidmajor: |
| 443 | *(__le64 *)&args->fsid.fsid[0] = cpu_to_le64(intval); |
| 444 | break; |
| 445 | case Opt_fsidminor: |
| 446 | *(__le64 *)&args->fsid.fsid[8] = cpu_to_le64(intval); |
| 447 | break; |
| 448 | case Opt_ip: |
| 449 | err = ceph_parse_ips(argstr[0].from, |
| 450 | argstr[0].to, |
| 451 | &args->my_addr, |
| 452 | 1, NULL); |
| 453 | if (err < 0) |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 454 | goto out; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 455 | args->flags |= CEPH_OPT_MYIP; |
| 456 | break; |
| 457 | |
| 458 | case Opt_snapdirname: |
| 459 | kfree(args->snapdir_name); |
| 460 | args->snapdir_name = kstrndup(argstr[0].from, |
| 461 | argstr[0].to-argstr[0].from, |
| 462 | GFP_KERNEL); |
| 463 | break; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 464 | case Opt_name: |
| 465 | args->name = kstrndup(argstr[0].from, |
| 466 | argstr[0].to-argstr[0].from, |
| 467 | GFP_KERNEL); |
| 468 | break; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 469 | case Opt_secret: |
| 470 | args->secret = kstrndup(argstr[0].from, |
| 471 | argstr[0].to-argstr[0].from, |
| 472 | GFP_KERNEL); |
| 473 | break; |
| 474 | |
| 475 | /* misc */ |
| 476 | case Opt_wsize: |
| 477 | args->wsize = intval; |
| 478 | break; |
| 479 | case Opt_rsize: |
| 480 | args->rsize = intval; |
| 481 | break; |
| 482 | case Opt_osdtimeout: |
| 483 | args->osd_timeout = intval; |
| 484 | break; |
Yehuda Sadeh | 422d2cb | 2010-02-26 15:32:31 -0800 | [diff] [blame] | 485 | case Opt_osdkeepalivetimeout: |
| 486 | args->osd_keepalive_timeout = intval; |
| 487 | break; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 488 | case Opt_mount_timeout: |
| 489 | args->mount_timeout = intval; |
| 490 | break; |
| 491 | case Opt_caps_wanted_delay_min: |
| 492 | args->caps_wanted_delay_min = intval; |
| 493 | break; |
| 494 | case Opt_caps_wanted_delay_max: |
| 495 | args->caps_wanted_delay_max = intval; |
| 496 | break; |
| 497 | case Opt_readdir_max_entries: |
| 498 | args->max_readdir = intval; |
| 499 | break; |
Yehuda Sadeh | 2baba25 | 2009-12-18 13:51:57 -0800 | [diff] [blame] | 500 | case Opt_congestion_kb: |
| 501 | args->congestion_kb = intval; |
| 502 | break; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 503 | |
| 504 | case Opt_noshare: |
| 505 | args->flags |= CEPH_OPT_NOSHARE; |
| 506 | break; |
| 507 | |
| 508 | case Opt_dirstat: |
| 509 | args->flags |= CEPH_OPT_DIRSTAT; |
| 510 | break; |
| 511 | case Opt_nodirstat: |
| 512 | args->flags &= ~CEPH_OPT_DIRSTAT; |
| 513 | break; |
| 514 | case Opt_rbytes: |
| 515 | args->flags |= CEPH_OPT_RBYTES; |
| 516 | break; |
| 517 | case Opt_norbytes: |
| 518 | args->flags &= ~CEPH_OPT_RBYTES; |
| 519 | break; |
| 520 | case Opt_nocrc: |
| 521 | args->flags |= CEPH_OPT_NOCRC; |
| 522 | break; |
| 523 | case Opt_noasyncreaddir: |
| 524 | args->flags |= CEPH_OPT_NOASYNCREADDIR; |
| 525 | break; |
| 526 | |
| 527 | default: |
| 528 | BUG_ON(token); |
| 529 | } |
| 530 | } |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 531 | return args; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 532 | |
Sage Weil | 7b813c46 | 2009-10-26 22:07:53 -0700 | [diff] [blame] | 533 | out: |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 534 | kfree(args->mon_addr); |
| 535 | kfree(args); |
| 536 | return ERR_PTR(err); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 539 | static void destroy_mount_args(struct ceph_mount_args *args) |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 540 | { |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 541 | dout("destroy_mount_args %p\n", args); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 542 | kfree(args->snapdir_name); |
| 543 | args->snapdir_name = NULL; |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 544 | kfree(args->name); |
| 545 | args->name = NULL; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 546 | kfree(args->secret); |
| 547 | args->secret = NULL; |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 548 | kfree(args); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | /* |
| 552 | * create a fresh client instance |
| 553 | */ |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 554 | static struct ceph_client *ceph_create_client(struct ceph_mount_args *args) |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 555 | { |
| 556 | struct ceph_client *client; |
| 557 | int err = -ENOMEM; |
| 558 | |
| 559 | client = kzalloc(sizeof(*client), GFP_KERNEL); |
| 560 | if (client == NULL) |
| 561 | return ERR_PTR(-ENOMEM); |
| 562 | |
| 563 | mutex_init(&client->mount_mutex); |
| 564 | |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 565 | init_waitqueue_head(&client->auth_wq); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 566 | |
| 567 | client->sb = NULL; |
| 568 | client->mount_state = CEPH_MOUNT_MOUNTING; |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 569 | client->mount_args = args; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 570 | |
| 571 | client->msgr = NULL; |
| 572 | |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 573 | client->auth_err = 0; |
Yehuda Sadeh | 2baba25 | 2009-12-18 13:51:57 -0800 | [diff] [blame] | 574 | atomic_long_set(&client->writeback_count, 0); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 575 | |
Sage Weil | 859e7b1 | 2009-11-02 09:32:47 -0800 | [diff] [blame] | 576 | err = bdi_init(&client->backing_dev_info); |
| 577 | if (err < 0) |
| 578 | goto fail; |
| 579 | |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 580 | err = -ENOMEM; |
| 581 | client->wb_wq = create_workqueue("ceph-writeback"); |
| 582 | if (client->wb_wq == NULL) |
Sage Weil | 859e7b1 | 2009-11-02 09:32:47 -0800 | [diff] [blame] | 583 | goto fail_bdi; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 584 | client->pg_inv_wq = create_singlethread_workqueue("ceph-pg-invalid"); |
| 585 | if (client->pg_inv_wq == NULL) |
| 586 | goto fail_wb_wq; |
| 587 | client->trunc_wq = create_singlethread_workqueue("ceph-trunc"); |
| 588 | if (client->trunc_wq == NULL) |
| 589 | goto fail_pg_inv_wq; |
| 590 | |
Sage Weil | b9bfb93 | 2009-11-18 15:08:44 -0800 | [diff] [blame] | 591 | /* set up mempools */ |
| 592 | err = -ENOMEM; |
| 593 | client->wb_pagevec_pool = mempool_create_kmalloc_pool(10, |
| 594 | client->mount_args->wsize >> PAGE_CACHE_SHIFT); |
| 595 | if (!client->wb_pagevec_pool) |
| 596 | goto fail_trunc_wq; |
| 597 | |
Sage Weil | 85ccce4 | 2010-02-17 10:02:43 -0800 | [diff] [blame] | 598 | /* caps */ |
| 599 | client->min_caps = args->max_readdir; |
| 600 | ceph_adjust_min_caps(client->min_caps); |
Sage Weil | b9bfb93 | 2009-11-18 15:08:44 -0800 | [diff] [blame] | 601 | |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 602 | /* subsystems */ |
| 603 | err = ceph_monc_init(&client->monc, client); |
| 604 | if (err < 0) |
Sage Weil | b9bfb93 | 2009-11-18 15:08:44 -0800 | [diff] [blame] | 605 | goto fail_mempool; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 606 | err = ceph_osdc_init(&client->osdc, client); |
| 607 | if (err < 0) |
| 608 | goto fail_monc; |
Sage Weil | 5f44f14 | 2009-11-18 14:52:18 -0800 | [diff] [blame] | 609 | err = ceph_mdsc_init(&client->mdsc, client); |
| 610 | if (err < 0) |
| 611 | goto fail_osdc; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 612 | return client; |
| 613 | |
Sage Weil | 5f44f14 | 2009-11-18 14:52:18 -0800 | [diff] [blame] | 614 | fail_osdc: |
| 615 | ceph_osdc_stop(&client->osdc); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 616 | fail_monc: |
| 617 | ceph_monc_stop(&client->monc); |
Sage Weil | b9bfb93 | 2009-11-18 15:08:44 -0800 | [diff] [blame] | 618 | fail_mempool: |
| 619 | mempool_destroy(client->wb_pagevec_pool); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 620 | fail_trunc_wq: |
| 621 | destroy_workqueue(client->trunc_wq); |
| 622 | fail_pg_inv_wq: |
| 623 | destroy_workqueue(client->pg_inv_wq); |
| 624 | fail_wb_wq: |
| 625 | destroy_workqueue(client->wb_wq); |
Sage Weil | 859e7b1 | 2009-11-02 09:32:47 -0800 | [diff] [blame] | 626 | fail_bdi: |
| 627 | bdi_destroy(&client->backing_dev_info); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 628 | fail: |
| 629 | kfree(client); |
| 630 | return ERR_PTR(err); |
| 631 | } |
| 632 | |
| 633 | static void ceph_destroy_client(struct ceph_client *client) |
| 634 | { |
| 635 | dout("destroy_client %p\n", client); |
| 636 | |
| 637 | /* unmount */ |
| 638 | ceph_mdsc_stop(&client->mdsc); |
| 639 | ceph_monc_stop(&client->monc); |
| 640 | ceph_osdc_stop(&client->osdc); |
| 641 | |
Sage Weil | 85ccce4 | 2010-02-17 10:02:43 -0800 | [diff] [blame] | 642 | ceph_adjust_min_caps(-client->min_caps); |
| 643 | |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 644 | ceph_debugfs_client_cleanup(client); |
| 645 | destroy_workqueue(client->wb_wq); |
| 646 | destroy_workqueue(client->pg_inv_wq); |
| 647 | destroy_workqueue(client->trunc_wq); |
| 648 | |
Sage Weil | 5dfc589 | 2010-05-04 16:14:46 -0700 | [diff] [blame] | 649 | bdi_destroy(&client->backing_dev_info); |
| 650 | |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 651 | if (client->msgr) |
| 652 | ceph_messenger_destroy(client->msgr); |
Sage Weil | b9bfb93 | 2009-11-18 15:08:44 -0800 | [diff] [blame] | 653 | mempool_destroy(client->wb_pagevec_pool); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 654 | |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 655 | destroy_mount_args(client->mount_args); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 656 | |
| 657 | kfree(client); |
| 658 | dout("destroy_client %p done\n", client); |
| 659 | } |
| 660 | |
| 661 | /* |
Sage Weil | 0743304 | 2009-11-18 16:50:41 -0800 | [diff] [blame] | 662 | * Initially learn our fsid, or verify an fsid matches. |
| 663 | */ |
| 664 | int ceph_check_fsid(struct ceph_client *client, struct ceph_fsid *fsid) |
| 665 | { |
| 666 | if (client->have_fsid) { |
| 667 | if (ceph_fsid_compare(&client->fsid, fsid)) { |
Sage Weil | 9ec7cab | 2009-12-14 15:13:47 -0800 | [diff] [blame] | 668 | pr_err("bad fsid, had " FSID_FORMAT " got " FSID_FORMAT, |
| 669 | PR_FSID(&client->fsid), PR_FSID(fsid)); |
Sage Weil | 0743304 | 2009-11-18 16:50:41 -0800 | [diff] [blame] | 670 | return -1; |
| 671 | } |
| 672 | } else { |
| 673 | pr_info("client%lld fsid " FSID_FORMAT "\n", |
| 674 | client->monc.auth->global_id, PR_FSID(fsid)); |
| 675 | memcpy(&client->fsid, fsid, sizeof(*fsid)); |
| 676 | ceph_debugfs_client_init(client); |
| 677 | client->have_fsid = true; |
| 678 | } |
| 679 | return 0; |
| 680 | } |
| 681 | |
| 682 | /* |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 683 | * true if we have the mon map (and have thus joined the cluster) |
| 684 | */ |
Sage Weil | 6822d00 | 2010-04-07 11:23:20 -0700 | [diff] [blame^] | 685 | static int have_mon_and_osd_map(struct ceph_client *client) |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 686 | { |
Sage Weil | 6822d00 | 2010-04-07 11:23:20 -0700 | [diff] [blame^] | 687 | return client->monc.monmap && client->monc.monmap->epoch && |
| 688 | client->osdc.osdmap && client->osdc.osdmap->epoch; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | /* |
| 692 | * Bootstrap mount by opening the root directory. Note the mount |
| 693 | * @started time from caller, and time out if this takes too long. |
| 694 | */ |
| 695 | static struct dentry *open_root_dentry(struct ceph_client *client, |
| 696 | const char *path, |
| 697 | unsigned long started) |
| 698 | { |
| 699 | struct ceph_mds_client *mdsc = &client->mdsc; |
| 700 | struct ceph_mds_request *req = NULL; |
| 701 | int err; |
| 702 | struct dentry *root; |
| 703 | |
| 704 | /* open dir */ |
| 705 | dout("open_root_inode opening '%s'\n", path); |
| 706 | req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_GETATTR, USE_ANY_MDS); |
| 707 | if (IS_ERR(req)) |
| 708 | return ERR_PTR(PTR_ERR(req)); |
| 709 | req->r_path1 = kstrdup(path, GFP_NOFS); |
| 710 | req->r_ino1.ino = CEPH_INO_ROOT; |
| 711 | req->r_ino1.snap = CEPH_NOSNAP; |
| 712 | req->r_started = started; |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 713 | req->r_timeout = client->mount_args->mount_timeout * HZ; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 714 | req->r_args.getattr.mask = cpu_to_le32(CEPH_STAT_CAP_INODE); |
| 715 | req->r_num_caps = 2; |
| 716 | err = ceph_mdsc_do_request(mdsc, NULL, req); |
| 717 | if (err == 0) { |
| 718 | dout("open_root_inode success\n"); |
| 719 | if (ceph_ino(req->r_target_inode) == CEPH_INO_ROOT && |
| 720 | client->sb->s_root == NULL) |
| 721 | root = d_alloc_root(req->r_target_inode); |
| 722 | else |
| 723 | root = d_obtain_alias(req->r_target_inode); |
| 724 | req->r_target_inode = NULL; |
| 725 | dout("open_root_inode success, root dentry is %p\n", root); |
| 726 | } else { |
| 727 | root = ERR_PTR(err); |
| 728 | } |
| 729 | ceph_mdsc_put_request(req); |
| 730 | return root; |
| 731 | } |
| 732 | |
| 733 | /* |
| 734 | * mount: join the ceph cluster, and open root directory. |
| 735 | */ |
| 736 | static int ceph_mount(struct ceph_client *client, struct vfsmount *mnt, |
| 737 | const char *path) |
| 738 | { |
| 739 | struct ceph_entity_addr *myaddr = NULL; |
| 740 | int err; |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 741 | unsigned long timeout = client->mount_args->mount_timeout * HZ; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 742 | unsigned long started = jiffies; /* note the start time */ |
| 743 | struct dentry *root; |
| 744 | |
| 745 | dout("mount start\n"); |
| 746 | mutex_lock(&client->mount_mutex); |
| 747 | |
| 748 | /* initialize the messenger */ |
| 749 | if (client->msgr == NULL) { |
| 750 | if (ceph_test_opt(client, MYIP)) |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 751 | myaddr = &client->mount_args->my_addr; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 752 | client->msgr = ceph_messenger_create(myaddr); |
| 753 | if (IS_ERR(client->msgr)) { |
| 754 | err = PTR_ERR(client->msgr); |
| 755 | client->msgr = NULL; |
| 756 | goto out; |
| 757 | } |
| 758 | client->msgr->nocrc = ceph_test_opt(client, NOCRC); |
| 759 | } |
| 760 | |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 761 | /* open session, and wait for mon, mds, and osd maps */ |
| 762 | err = ceph_monc_open_session(&client->monc); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 763 | if (err < 0) |
| 764 | goto out; |
| 765 | |
Sage Weil | 6822d00 | 2010-04-07 11:23:20 -0700 | [diff] [blame^] | 766 | while (!have_mon_and_osd_map(client)) { |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 767 | err = -EIO; |
| 768 | if (timeout && time_after_eq(jiffies, started + timeout)) |
| 769 | goto out; |
| 770 | |
| 771 | /* wait */ |
Sage Weil | 4e7a5dc | 2009-11-18 16:19:57 -0800 | [diff] [blame] | 772 | dout("mount waiting for mon_map\n"); |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 773 | err = wait_event_interruptible_timeout(client->auth_wq, |
Sage Weil | 6822d00 | 2010-04-07 11:23:20 -0700 | [diff] [blame^] | 774 | have_mon_and_osd_map(client) || (client->auth_err < 0), |
| 775 | timeout); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 776 | if (err == -EINTR || err == -ERESTARTSYS) |
| 777 | goto out; |
Sage Weil | 9bd2e6f | 2010-02-02 16:21:06 -0800 | [diff] [blame] | 778 | if (client->auth_err < 0) { |
| 779 | err = client->auth_err; |
Yehuda Sadeh | dc14657 | 2009-11-20 13:59:13 -0800 | [diff] [blame] | 780 | goto out; |
| 781 | } |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | dout("mount opening root\n"); |
| 785 | root = open_root_dentry(client, "", started); |
| 786 | if (IS_ERR(root)) { |
| 787 | err = PTR_ERR(root); |
| 788 | goto out; |
| 789 | } |
| 790 | if (client->sb->s_root) |
| 791 | dput(root); |
| 792 | else |
| 793 | client->sb->s_root = root; |
| 794 | |
| 795 | if (path[0] == 0) { |
| 796 | dget(root); |
| 797 | } else { |
| 798 | dout("mount opening base mountpoint\n"); |
| 799 | root = open_root_dentry(client, path, started); |
| 800 | if (IS_ERR(root)) { |
| 801 | err = PTR_ERR(root); |
| 802 | dput(client->sb->s_root); |
| 803 | client->sb->s_root = NULL; |
| 804 | goto out; |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | mnt->mnt_root = root; |
| 809 | mnt->mnt_sb = client->sb; |
| 810 | |
| 811 | client->mount_state = CEPH_MOUNT_MOUNTED; |
| 812 | dout("mount success\n"); |
| 813 | err = 0; |
| 814 | |
| 815 | out: |
| 816 | mutex_unlock(&client->mount_mutex); |
| 817 | return err; |
| 818 | } |
| 819 | |
| 820 | static int ceph_set_super(struct super_block *s, void *data) |
| 821 | { |
| 822 | struct ceph_client *client = data; |
| 823 | int ret; |
| 824 | |
| 825 | dout("set_super %p data %p\n", s, data); |
| 826 | |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 827 | s->s_flags = client->mount_args->sb_flags; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 828 | s->s_maxbytes = 1ULL << 40; /* temp value until we get mdsmap */ |
| 829 | |
| 830 | s->s_fs_info = client; |
| 831 | client->sb = s; |
| 832 | |
| 833 | s->s_op = &ceph_super_ops; |
| 834 | s->s_export_op = &ceph_export_ops; |
| 835 | |
| 836 | s->s_time_gran = 1000; /* 1000 ns == 1 us */ |
| 837 | |
| 838 | ret = set_anon_super(s, NULL); /* what is that second arg for? */ |
| 839 | if (ret != 0) |
| 840 | goto fail; |
| 841 | |
| 842 | return ret; |
| 843 | |
| 844 | fail: |
| 845 | s->s_fs_info = NULL; |
| 846 | client->sb = NULL; |
| 847 | return ret; |
| 848 | } |
| 849 | |
| 850 | /* |
| 851 | * share superblock if same fs AND options |
| 852 | */ |
| 853 | static int ceph_compare_super(struct super_block *sb, void *data) |
| 854 | { |
| 855 | struct ceph_client *new = data; |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 856 | struct ceph_mount_args *args = new->mount_args; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 857 | struct ceph_client *other = ceph_sb_to_client(sb); |
| 858 | int i; |
| 859 | |
| 860 | dout("ceph_compare_super %p\n", sb); |
| 861 | if (args->flags & CEPH_OPT_FSID) { |
| 862 | if (ceph_fsid_compare(&args->fsid, &other->fsid)) { |
| 863 | dout("fsid doesn't match\n"); |
| 864 | return 0; |
| 865 | } |
| 866 | } else { |
| 867 | /* do we share (a) monitor? */ |
| 868 | for (i = 0; i < new->monc.monmap->num_mon; i++) |
| 869 | if (ceph_monmap_contains(other->monc.monmap, |
| 870 | &new->monc.monmap->mon_inst[i].addr)) |
| 871 | break; |
| 872 | if (i == new->monc.monmap->num_mon) { |
| 873 | dout("mon ip not part of monmap\n"); |
| 874 | return 0; |
| 875 | } |
| 876 | dout("mon ip matches existing sb %p\n", sb); |
| 877 | } |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 878 | if (args->sb_flags != other->mount_args->sb_flags) { |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 879 | dout("flags differ\n"); |
| 880 | return 0; |
| 881 | } |
| 882 | return 1; |
| 883 | } |
| 884 | |
| 885 | /* |
| 886 | * construct our own bdi so we can control readahead, etc. |
| 887 | */ |
Sage Weil | 859e7b1 | 2009-11-02 09:32:47 -0800 | [diff] [blame] | 888 | static int ceph_register_bdi(struct super_block *sb, struct ceph_client *client) |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 889 | { |
| 890 | int err; |
| 891 | |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 892 | /* set ra_pages based on rsize mount option? */ |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 893 | if (client->mount_args->rsize >= PAGE_CACHE_SIZE) |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 894 | client->backing_dev_info.ra_pages = |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 895 | (client->mount_args->rsize + PAGE_CACHE_SIZE - 1) |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 896 | >> PAGE_SHIFT; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 897 | err = bdi_register_dev(&client->backing_dev_info, sb->s_dev); |
Sage Weil | 5dfc589 | 2010-05-04 16:14:46 -0700 | [diff] [blame] | 898 | if (!err) |
| 899 | sb->s_bdi = &client->backing_dev_info; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 900 | return err; |
| 901 | } |
| 902 | |
| 903 | static int ceph_get_sb(struct file_system_type *fs_type, |
| 904 | int flags, const char *dev_name, void *data, |
| 905 | struct vfsmount *mnt) |
| 906 | { |
| 907 | struct super_block *sb; |
| 908 | struct ceph_client *client; |
| 909 | int err; |
| 910 | int (*compare_super)(struct super_block *, void *) = ceph_compare_super; |
Sage Weil | 6a18be1 | 2009-11-04 11:40:05 -0800 | [diff] [blame] | 911 | const char *path = NULL; |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 912 | struct ceph_mount_args *args; |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 913 | |
| 914 | dout("ceph_get_sb\n"); |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 915 | args = parse_mount_args(flags, data, dev_name, &path); |
| 916 | if (IS_ERR(args)) { |
| 917 | err = PTR_ERR(args); |
| 918 | goto out_final; |
| 919 | } |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 920 | |
| 921 | /* create client (which we may/may not use) */ |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 922 | client = ceph_create_client(args); |
| 923 | if (IS_ERR(client)) { |
| 924 | err = PTR_ERR(client); |
| 925 | goto out_final; |
| 926 | } |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 927 | |
Sage Weil | 6b80518 | 2009-10-27 11:50:50 -0700 | [diff] [blame] | 928 | if (client->mount_args->flags & CEPH_OPT_NOSHARE) |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 929 | compare_super = NULL; |
| 930 | sb = sget(fs_type, compare_super, ceph_set_super, client); |
| 931 | if (IS_ERR(sb)) { |
| 932 | err = PTR_ERR(sb); |
| 933 | goto out; |
| 934 | } |
| 935 | |
Cheng Renquan | 640ef79 | 2010-03-26 17:40:33 +0800 | [diff] [blame] | 936 | if (ceph_sb_to_client(sb) != client) { |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 937 | ceph_destroy_client(client); |
Cheng Renquan | 640ef79 | 2010-03-26 17:40:33 +0800 | [diff] [blame] | 938 | client = ceph_sb_to_client(sb); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 939 | dout("get_sb got existing client %p\n", client); |
| 940 | } else { |
| 941 | dout("get_sb using new client %p\n", client); |
Sage Weil | 859e7b1 | 2009-11-02 09:32:47 -0800 | [diff] [blame] | 942 | err = ceph_register_bdi(sb, client); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 943 | if (err < 0) |
| 944 | goto out_splat; |
| 945 | } |
| 946 | |
| 947 | err = ceph_mount(client, mnt, path); |
| 948 | if (err < 0) |
| 949 | goto out_splat; |
| 950 | dout("root %p inode %p ino %llx.%llx\n", mnt->mnt_root, |
| 951 | mnt->mnt_root->d_inode, ceph_vinop(mnt->mnt_root->d_inode)); |
| 952 | return 0; |
| 953 | |
| 954 | out_splat: |
| 955 | ceph_mdsc_close_sessions(&client->mdsc); |
| 956 | up_write(&sb->s_umount); |
| 957 | deactivate_super(sb); |
| 958 | goto out_final; |
| 959 | |
| 960 | out: |
| 961 | ceph_destroy_client(client); |
| 962 | out_final: |
| 963 | dout("ceph_get_sb fail %d\n", err); |
| 964 | return err; |
| 965 | } |
| 966 | |
| 967 | static void ceph_kill_sb(struct super_block *s) |
| 968 | { |
| 969 | struct ceph_client *client = ceph_sb_to_client(s); |
| 970 | dout("kill_sb %p\n", s); |
| 971 | ceph_mdsc_pre_umount(&client->mdsc); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 972 | kill_anon_super(s); /* will call put_super after sb is r/o */ |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 973 | ceph_destroy_client(client); |
| 974 | } |
| 975 | |
| 976 | static struct file_system_type ceph_fs_type = { |
| 977 | .owner = THIS_MODULE, |
| 978 | .name = "ceph", |
| 979 | .get_sb = ceph_get_sb, |
| 980 | .kill_sb = ceph_kill_sb, |
| 981 | .fs_flags = FS_RENAME_DOES_D_MOVE, |
| 982 | }; |
| 983 | |
| 984 | #define _STRINGIFY(x) #x |
| 985 | #define STRINGIFY(x) _STRINGIFY(x) |
| 986 | |
| 987 | static int __init init_ceph(void) |
| 988 | { |
| 989 | int ret = 0; |
| 990 | |
| 991 | ret = ceph_debugfs_init(); |
| 992 | if (ret < 0) |
| 993 | goto out; |
| 994 | |
| 995 | ret = ceph_msgr_init(); |
| 996 | if (ret < 0) |
| 997 | goto out_debugfs; |
| 998 | |
| 999 | ret = init_caches(); |
| 1000 | if (ret) |
| 1001 | goto out_msgr; |
| 1002 | |
| 1003 | ceph_caps_init(); |
| 1004 | |
| 1005 | ret = register_filesystem(&ceph_fs_type); |
| 1006 | if (ret) |
| 1007 | goto out_icache; |
| 1008 | |
Sage Weil | c8f1658 | 2010-04-19 13:50:26 -0700 | [diff] [blame] | 1009 | pr_info("loaded (mon/mds/osd proto %d/%d/%d, osdmap %d/%d %d/%d)\n", |
| 1010 | CEPH_MONC_PROTOCOL, CEPH_MDSC_PROTOCOL, CEPH_OSDC_PROTOCOL, |
| 1011 | CEPH_OSDMAP_VERSION, CEPH_OSDMAP_VERSION_EXT, |
| 1012 | CEPH_OSDMAP_INC_VERSION, CEPH_OSDMAP_INC_VERSION_EXT); |
Sage Weil | 16725b9 | 2009-10-06 11:31:07 -0700 | [diff] [blame] | 1013 | return 0; |
| 1014 | |
| 1015 | out_icache: |
| 1016 | destroy_caches(); |
| 1017 | out_msgr: |
| 1018 | ceph_msgr_exit(); |
| 1019 | out_debugfs: |
| 1020 | ceph_debugfs_cleanup(); |
| 1021 | out: |
| 1022 | return ret; |
| 1023 | } |
| 1024 | |
| 1025 | static void __exit exit_ceph(void) |
| 1026 | { |
| 1027 | dout("exit_ceph\n"); |
| 1028 | unregister_filesystem(&ceph_fs_type); |
| 1029 | ceph_caps_finalize(); |
| 1030 | destroy_caches(); |
| 1031 | ceph_msgr_exit(); |
| 1032 | ceph_debugfs_cleanup(); |
| 1033 | } |
| 1034 | |
| 1035 | module_init(init_ceph); |
| 1036 | module_exit(exit_ceph); |
| 1037 | |
| 1038 | MODULE_AUTHOR("Sage Weil <sage@newdream.net>"); |
| 1039 | MODULE_AUTHOR("Yehuda Sadeh <yehuda@hq.newdream.net>"); |
| 1040 | MODULE_AUTHOR("Patience Warnick <patience@newdream.net>"); |
| 1041 | MODULE_DESCRIPTION("Ceph filesystem for Linux"); |
| 1042 | MODULE_LICENSE("GPL"); |