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