13d14c5d2SYehuda Sadeh 23d14c5d2SYehuda Sadeh #include <linux/ceph/ceph_debug.h> 33d14c5d2SYehuda Sadeh #include <linux/backing-dev.h> 43d14c5d2SYehuda Sadeh #include <linux/ctype.h> 53d14c5d2SYehuda Sadeh #include <linux/fs.h> 63d14c5d2SYehuda Sadeh #include <linux/inet.h> 73d14c5d2SYehuda Sadeh #include <linux/in6.h> 8e2c3d29bSTommi Virtanen #include <linux/key.h> 94b2a58abSTommi Virtanen #include <keys/ceph-type.h> 103d14c5d2SYehuda Sadeh #include <linux/module.h> 113d14c5d2SYehuda Sadeh #include <linux/mount.h> 123d14c5d2SYehuda Sadeh #include <linux/parser.h> 133d14c5d2SYehuda Sadeh #include <linux/sched.h> 143d14c5d2SYehuda Sadeh #include <linux/seq_file.h> 153d14c5d2SYehuda Sadeh #include <linux/slab.h> 163d14c5d2SYehuda Sadeh #include <linux/statfs.h> 173d14c5d2SYehuda Sadeh #include <linux/string.h> 18eeb0bed5SIlya Dryomov #include <linux/vmalloc.h> 19eea553c2SEric W. Biederman #include <linux/nsproxy.h> 20eea553c2SEric W. Biederman #include <net/net_namespace.h> 213d14c5d2SYehuda Sadeh 223d14c5d2SYehuda Sadeh 231fe60e51SSage Weil #include <linux/ceph/ceph_features.h> 243d14c5d2SYehuda Sadeh #include <linux/ceph/libceph.h> 253d14c5d2SYehuda Sadeh #include <linux/ceph/debugfs.h> 263d14c5d2SYehuda Sadeh #include <linux/ceph/decode.h> 273d14c5d2SYehuda Sadeh #include <linux/ceph/mon_client.h> 283d14c5d2SYehuda Sadeh #include <linux/ceph/auth.h> 298323c3aaSTommi Virtanen #include "crypto.h" 303d14c5d2SYehuda Sadeh 313d14c5d2SYehuda Sadeh 3272fe25e3SAlex Elder /* 3372fe25e3SAlex Elder * Module compatibility interface. For now it doesn't do anything, 3472fe25e3SAlex Elder * but its existence signals a certain level of functionality. 3572fe25e3SAlex Elder * 3672fe25e3SAlex Elder * The data buffer is used to pass information both to and from 3772fe25e3SAlex Elder * libceph. The return value indicates whether libceph determines 3872fe25e3SAlex Elder * it is compatible with the caller (from another kernel module), 3972fe25e3SAlex Elder * given the provided data. 4072fe25e3SAlex Elder * 4172fe25e3SAlex Elder * The data pointer can be null. 4272fe25e3SAlex Elder */ 4372fe25e3SAlex Elder bool libceph_compatible(void *data) 4472fe25e3SAlex Elder { 451e32d34cSAlex Elder return true; 4672fe25e3SAlex Elder } 4772fe25e3SAlex Elder EXPORT_SYMBOL(libceph_compatible); 483d14c5d2SYehuda Sadeh 493d14c5d2SYehuda Sadeh /* 503d14c5d2SYehuda Sadeh * find filename portion of a path (/foo/bar/baz -> baz) 513d14c5d2SYehuda Sadeh */ 523d14c5d2SYehuda Sadeh const char *ceph_file_part(const char *s, int len) 533d14c5d2SYehuda Sadeh { 543d14c5d2SYehuda Sadeh const char *e = s + len; 553d14c5d2SYehuda Sadeh 563d14c5d2SYehuda Sadeh while (e != s && *(e-1) != '/') 573d14c5d2SYehuda Sadeh e--; 583d14c5d2SYehuda Sadeh return e; 593d14c5d2SYehuda Sadeh } 603d14c5d2SYehuda Sadeh EXPORT_SYMBOL(ceph_file_part); 613d14c5d2SYehuda Sadeh 623d14c5d2SYehuda Sadeh const char *ceph_msg_type_name(int type) 633d14c5d2SYehuda Sadeh { 643d14c5d2SYehuda Sadeh switch (type) { 653d14c5d2SYehuda Sadeh case CEPH_MSG_SHUTDOWN: return "shutdown"; 663d14c5d2SYehuda Sadeh case CEPH_MSG_PING: return "ping"; 673d14c5d2SYehuda Sadeh case CEPH_MSG_AUTH: return "auth"; 683d14c5d2SYehuda Sadeh case CEPH_MSG_AUTH_REPLY: return "auth_reply"; 693d14c5d2SYehuda Sadeh case CEPH_MSG_MON_MAP: return "mon_map"; 703d14c5d2SYehuda Sadeh case CEPH_MSG_MON_GET_MAP: return "mon_get_map"; 713d14c5d2SYehuda Sadeh case CEPH_MSG_MON_SUBSCRIBE: return "mon_subscribe"; 723d14c5d2SYehuda Sadeh case CEPH_MSG_MON_SUBSCRIBE_ACK: return "mon_subscribe_ack"; 733d14c5d2SYehuda Sadeh case CEPH_MSG_STATFS: return "statfs"; 743d14c5d2SYehuda Sadeh case CEPH_MSG_STATFS_REPLY: return "statfs_reply"; 75513a8243SIlya Dryomov case CEPH_MSG_MON_GET_VERSION: return "mon_get_version"; 76513a8243SIlya Dryomov case CEPH_MSG_MON_GET_VERSION_REPLY: return "mon_get_version_reply"; 773d14c5d2SYehuda Sadeh case CEPH_MSG_MDS_MAP: return "mds_map"; 783d14c5d2SYehuda Sadeh case CEPH_MSG_CLIENT_SESSION: return "client_session"; 793d14c5d2SYehuda Sadeh case CEPH_MSG_CLIENT_RECONNECT: return "client_reconnect"; 803d14c5d2SYehuda Sadeh case CEPH_MSG_CLIENT_REQUEST: return "client_request"; 813d14c5d2SYehuda Sadeh case CEPH_MSG_CLIENT_REQUEST_FORWARD: return "client_request_forward"; 823d14c5d2SYehuda Sadeh case CEPH_MSG_CLIENT_REPLY: return "client_reply"; 833d14c5d2SYehuda Sadeh case CEPH_MSG_CLIENT_CAPS: return "client_caps"; 843d14c5d2SYehuda Sadeh case CEPH_MSG_CLIENT_CAPRELEASE: return "client_cap_release"; 853d14c5d2SYehuda Sadeh case CEPH_MSG_CLIENT_SNAP: return "client_snap"; 863d14c5d2SYehuda Sadeh case CEPH_MSG_CLIENT_LEASE: return "client_lease"; 873d14c5d2SYehuda Sadeh case CEPH_MSG_OSD_MAP: return "osd_map"; 883d14c5d2SYehuda Sadeh case CEPH_MSG_OSD_OP: return "osd_op"; 893d14c5d2SYehuda Sadeh case CEPH_MSG_OSD_OPREPLY: return "osd_opreply"; 90a40c4f10SYehuda Sadeh case CEPH_MSG_WATCH_NOTIFY: return "watch_notify"; 913d14c5d2SYehuda Sadeh default: return "unknown"; 923d14c5d2SYehuda Sadeh } 933d14c5d2SYehuda Sadeh } 943d14c5d2SYehuda Sadeh EXPORT_SYMBOL(ceph_msg_type_name); 953d14c5d2SYehuda Sadeh 963d14c5d2SYehuda Sadeh /* 973d14c5d2SYehuda Sadeh * Initially learn our fsid, or verify an fsid matches. 983d14c5d2SYehuda Sadeh */ 993d14c5d2SYehuda Sadeh int ceph_check_fsid(struct ceph_client *client, struct ceph_fsid *fsid) 1003d14c5d2SYehuda Sadeh { 1013d14c5d2SYehuda Sadeh if (client->have_fsid) { 1023d14c5d2SYehuda Sadeh if (ceph_fsid_compare(&client->fsid, fsid)) { 1033d14c5d2SYehuda Sadeh pr_err("bad fsid, had %pU got %pU", 1043d14c5d2SYehuda Sadeh &client->fsid, fsid); 1053d14c5d2SYehuda Sadeh return -1; 1063d14c5d2SYehuda Sadeh } 1073d14c5d2SYehuda Sadeh } else { 1083d14c5d2SYehuda Sadeh memcpy(&client->fsid, fsid, sizeof(*fsid)); 1093d14c5d2SYehuda Sadeh } 1103d14c5d2SYehuda Sadeh return 0; 1113d14c5d2SYehuda Sadeh } 1123d14c5d2SYehuda Sadeh EXPORT_SYMBOL(ceph_check_fsid); 1133d14c5d2SYehuda Sadeh 1143d14c5d2SYehuda Sadeh static int strcmp_null(const char *s1, const char *s2) 1153d14c5d2SYehuda Sadeh { 1163d14c5d2SYehuda Sadeh if (!s1 && !s2) 1173d14c5d2SYehuda Sadeh return 0; 1183d14c5d2SYehuda Sadeh if (s1 && !s2) 1193d14c5d2SYehuda Sadeh return -1; 1203d14c5d2SYehuda Sadeh if (!s1 && s2) 1213d14c5d2SYehuda Sadeh return 1; 1223d14c5d2SYehuda Sadeh return strcmp(s1, s2); 1233d14c5d2SYehuda Sadeh } 1243d14c5d2SYehuda Sadeh 1253d14c5d2SYehuda Sadeh int ceph_compare_options(struct ceph_options *new_opt, 1263d14c5d2SYehuda Sadeh struct ceph_client *client) 1273d14c5d2SYehuda Sadeh { 1283d14c5d2SYehuda Sadeh struct ceph_options *opt1 = new_opt; 1293d14c5d2SYehuda Sadeh struct ceph_options *opt2 = client->options; 1303d14c5d2SYehuda Sadeh int ofs = offsetof(struct ceph_options, mon_addr); 1313d14c5d2SYehuda Sadeh int i; 1323d14c5d2SYehuda Sadeh int ret; 1333d14c5d2SYehuda Sadeh 1343d14c5d2SYehuda Sadeh ret = memcmp(opt1, opt2, ofs); 1353d14c5d2SYehuda Sadeh if (ret) 1363d14c5d2SYehuda Sadeh return ret; 1373d14c5d2SYehuda Sadeh 1383d14c5d2SYehuda Sadeh ret = strcmp_null(opt1->name, opt2->name); 1393d14c5d2SYehuda Sadeh if (ret) 1403d14c5d2SYehuda Sadeh return ret; 1413d14c5d2SYehuda Sadeh 1428323c3aaSTommi Virtanen if (opt1->key && !opt2->key) 1438323c3aaSTommi Virtanen return -1; 1448323c3aaSTommi Virtanen if (!opt1->key && opt2->key) 1458323c3aaSTommi Virtanen return 1; 1468323c3aaSTommi Virtanen if (opt1->key && opt2->key) { 1478323c3aaSTommi Virtanen if (opt1->key->type != opt2->key->type) 1488323c3aaSTommi Virtanen return -1; 1498323c3aaSTommi Virtanen if (opt1->key->created.tv_sec != opt2->key->created.tv_sec) 1508323c3aaSTommi Virtanen return -1; 1518323c3aaSTommi Virtanen if (opt1->key->created.tv_nsec != opt2->key->created.tv_nsec) 1528323c3aaSTommi Virtanen return -1; 1538323c3aaSTommi Virtanen if (opt1->key->len != opt2->key->len) 1548323c3aaSTommi Virtanen return -1; 1558323c3aaSTommi Virtanen if (opt1->key->key && !opt2->key->key) 1568323c3aaSTommi Virtanen return -1; 1578323c3aaSTommi Virtanen if (!opt1->key->key && opt2->key->key) 1588323c3aaSTommi Virtanen return 1; 1598323c3aaSTommi Virtanen if (opt1->key->key && opt2->key->key) { 1608323c3aaSTommi Virtanen ret = memcmp(opt1->key->key, opt2->key->key, opt1->key->len); 1613d14c5d2SYehuda Sadeh if (ret) 1623d14c5d2SYehuda Sadeh return ret; 1638323c3aaSTommi Virtanen } 1648323c3aaSTommi Virtanen } 1653d14c5d2SYehuda Sadeh 1663d14c5d2SYehuda Sadeh /* any matching mon ip implies a match */ 1673d14c5d2SYehuda Sadeh for (i = 0; i < opt1->num_mon; i++) { 1683d14c5d2SYehuda Sadeh if (ceph_monmap_contains(client->monc.monmap, 1693d14c5d2SYehuda Sadeh &opt1->mon_addr[i])) 1703d14c5d2SYehuda Sadeh return 0; 1713d14c5d2SYehuda Sadeh } 1723d14c5d2SYehuda Sadeh return -1; 1733d14c5d2SYehuda Sadeh } 1743d14c5d2SYehuda Sadeh EXPORT_SYMBOL(ceph_compare_options); 1753d14c5d2SYehuda Sadeh 176eeb0bed5SIlya Dryomov void *ceph_kvmalloc(size_t size, gfp_t flags) 177eeb0bed5SIlya Dryomov { 178eeb0bed5SIlya Dryomov if (size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER)) { 179eeb0bed5SIlya Dryomov void *ptr = kmalloc(size, flags | __GFP_NOWARN); 180eeb0bed5SIlya Dryomov if (ptr) 181eeb0bed5SIlya Dryomov return ptr; 182eeb0bed5SIlya Dryomov } 183eeb0bed5SIlya Dryomov 184eeb0bed5SIlya Dryomov return __vmalloc(size, flags | __GFP_HIGHMEM, PAGE_KERNEL); 185eeb0bed5SIlya Dryomov } 186eeb0bed5SIlya Dryomov 1873d14c5d2SYehuda Sadeh 1883d14c5d2SYehuda Sadeh static int parse_fsid(const char *str, struct ceph_fsid *fsid) 1893d14c5d2SYehuda Sadeh { 1903d14c5d2SYehuda Sadeh int i = 0; 1913d14c5d2SYehuda Sadeh char tmp[3]; 1923d14c5d2SYehuda Sadeh int err = -EINVAL; 1933d14c5d2SYehuda Sadeh int d; 1943d14c5d2SYehuda Sadeh 1953d14c5d2SYehuda Sadeh dout("parse_fsid '%s'\n", str); 1963d14c5d2SYehuda Sadeh tmp[2] = 0; 1973d14c5d2SYehuda Sadeh while (*str && i < 16) { 1983d14c5d2SYehuda Sadeh if (ispunct(*str)) { 1993d14c5d2SYehuda Sadeh str++; 2003d14c5d2SYehuda Sadeh continue; 2013d14c5d2SYehuda Sadeh } 2023d14c5d2SYehuda Sadeh if (!isxdigit(str[0]) || !isxdigit(str[1])) 2033d14c5d2SYehuda Sadeh break; 2043d14c5d2SYehuda Sadeh tmp[0] = str[0]; 2053d14c5d2SYehuda Sadeh tmp[1] = str[1]; 2063d14c5d2SYehuda Sadeh if (sscanf(tmp, "%x", &d) < 1) 2073d14c5d2SYehuda Sadeh break; 2083d14c5d2SYehuda Sadeh fsid->fsid[i] = d & 0xff; 2093d14c5d2SYehuda Sadeh i++; 2103d14c5d2SYehuda Sadeh str += 2; 2113d14c5d2SYehuda Sadeh } 2123d14c5d2SYehuda Sadeh 2133d14c5d2SYehuda Sadeh if (i == 16) 2143d14c5d2SYehuda Sadeh err = 0; 2153d14c5d2SYehuda Sadeh dout("parse_fsid ret %d got fsid %pU", err, fsid); 2163d14c5d2SYehuda Sadeh return err; 2173d14c5d2SYehuda Sadeh } 2183d14c5d2SYehuda Sadeh 2193d14c5d2SYehuda Sadeh /* 2203d14c5d2SYehuda Sadeh * ceph options 2213d14c5d2SYehuda Sadeh */ 2223d14c5d2SYehuda Sadeh enum { 2233d14c5d2SYehuda Sadeh Opt_osdtimeout, 2243d14c5d2SYehuda Sadeh Opt_osdkeepalivetimeout, 2253d14c5d2SYehuda Sadeh Opt_mount_timeout, 2263d14c5d2SYehuda Sadeh Opt_osd_idle_ttl, 2273d14c5d2SYehuda Sadeh Opt_last_int, 2283d14c5d2SYehuda Sadeh /* int args above */ 2293d14c5d2SYehuda Sadeh Opt_fsid, 2303d14c5d2SYehuda Sadeh Opt_name, 2313d14c5d2SYehuda Sadeh Opt_secret, 232e2c3d29bSTommi Virtanen Opt_key, 2333d14c5d2SYehuda Sadeh Opt_ip, 2343d14c5d2SYehuda Sadeh Opt_last_string, 2353d14c5d2SYehuda Sadeh /* string args above */ 236cffaba15SAlex Elder Opt_share, 2373d14c5d2SYehuda Sadeh Opt_noshare, 238cffaba15SAlex Elder Opt_crc, 2393d14c5d2SYehuda Sadeh Opt_nocrc, 240a3fc9800SYan, Zheng Opt_cephx_require_signatures, 241a3fc9800SYan, Zheng Opt_nocephx_require_signatures, 242ba988f87SChaitanya Huilgol Opt_tcp_nodelay, 243ba988f87SChaitanya Huilgol Opt_notcp_nodelay, 2443d14c5d2SYehuda Sadeh }; 2453d14c5d2SYehuda Sadeh 2463d14c5d2SYehuda Sadeh static match_table_t opt_tokens = { 2473d14c5d2SYehuda Sadeh {Opt_osdtimeout, "osdtimeout=%d"}, 2483d14c5d2SYehuda Sadeh {Opt_osdkeepalivetimeout, "osdkeepalive=%d"}, 2493d14c5d2SYehuda Sadeh {Opt_mount_timeout, "mount_timeout=%d"}, 2503d14c5d2SYehuda Sadeh {Opt_osd_idle_ttl, "osd_idle_ttl=%d"}, 2513d14c5d2SYehuda Sadeh /* int args above */ 2523d14c5d2SYehuda Sadeh {Opt_fsid, "fsid=%s"}, 2533d14c5d2SYehuda Sadeh {Opt_name, "name=%s"}, 2543d14c5d2SYehuda Sadeh {Opt_secret, "secret=%s"}, 255e2c3d29bSTommi Virtanen {Opt_key, "key=%s"}, 2563d14c5d2SYehuda Sadeh {Opt_ip, "ip=%s"}, 2573d14c5d2SYehuda Sadeh /* string args above */ 258cffaba15SAlex Elder {Opt_share, "share"}, 2593d14c5d2SYehuda Sadeh {Opt_noshare, "noshare"}, 260cffaba15SAlex Elder {Opt_crc, "crc"}, 2613d14c5d2SYehuda Sadeh {Opt_nocrc, "nocrc"}, 262a3fc9800SYan, Zheng {Opt_cephx_require_signatures, "cephx_require_signatures"}, 263a3fc9800SYan, Zheng {Opt_nocephx_require_signatures, "nocephx_require_signatures"}, 264ba988f87SChaitanya Huilgol {Opt_tcp_nodelay, "tcp_nodelay"}, 265ba988f87SChaitanya Huilgol {Opt_notcp_nodelay, "notcp_nodelay"}, 2663d14c5d2SYehuda Sadeh {-1, NULL} 2673d14c5d2SYehuda Sadeh }; 2683d14c5d2SYehuda Sadeh 2693d14c5d2SYehuda Sadeh void ceph_destroy_options(struct ceph_options *opt) 2703d14c5d2SYehuda Sadeh { 2713d14c5d2SYehuda Sadeh dout("destroy_options %p\n", opt); 2723d14c5d2SYehuda Sadeh kfree(opt->name); 2738323c3aaSTommi Virtanen if (opt->key) { 2748323c3aaSTommi Virtanen ceph_crypto_key_destroy(opt->key); 2758323c3aaSTommi Virtanen kfree(opt->key); 2768323c3aaSTommi Virtanen } 2771cad7893SNoah Watkins kfree(opt->mon_addr); 2783d14c5d2SYehuda Sadeh kfree(opt); 2793d14c5d2SYehuda Sadeh } 2803d14c5d2SYehuda Sadeh EXPORT_SYMBOL(ceph_destroy_options); 2813d14c5d2SYehuda Sadeh 282e2c3d29bSTommi Virtanen /* get secret from key store */ 283e2c3d29bSTommi Virtanen static int get_secret(struct ceph_crypto_key *dst, const char *name) { 284e2c3d29bSTommi Virtanen struct key *ukey; 285e2c3d29bSTommi Virtanen int key_err; 286e2c3d29bSTommi Virtanen int err = 0; 2874b2a58abSTommi Virtanen struct ceph_crypto_key *ckey; 288e2c3d29bSTommi Virtanen 2894b2a58abSTommi Virtanen ukey = request_key(&key_type_ceph, name, NULL); 290e2c3d29bSTommi Virtanen if (!ukey || IS_ERR(ukey)) { 291e2c3d29bSTommi Virtanen /* request_key errors don't map nicely to mount(2) 292e2c3d29bSTommi Virtanen errors; don't even try, but still printk */ 293e2c3d29bSTommi Virtanen key_err = PTR_ERR(ukey); 294e2c3d29bSTommi Virtanen switch (key_err) { 295e2c3d29bSTommi Virtanen case -ENOKEY: 296b9a67899SJoe Perches pr_warn("ceph: Mount failed due to key not found: %s\n", 297b9a67899SJoe Perches name); 298e2c3d29bSTommi Virtanen break; 299e2c3d29bSTommi Virtanen case -EKEYEXPIRED: 300b9a67899SJoe Perches pr_warn("ceph: Mount failed due to expired key: %s\n", 301b9a67899SJoe Perches name); 302e2c3d29bSTommi Virtanen break; 303e2c3d29bSTommi Virtanen case -EKEYREVOKED: 304b9a67899SJoe Perches pr_warn("ceph: Mount failed due to revoked key: %s\n", 305b9a67899SJoe Perches name); 306e2c3d29bSTommi Virtanen break; 307e2c3d29bSTommi Virtanen default: 308b9a67899SJoe Perches pr_warn("ceph: Mount failed due to unknown key error %d: %s\n", 309b9a67899SJoe Perches key_err, name); 310e2c3d29bSTommi Virtanen } 311e2c3d29bSTommi Virtanen err = -EPERM; 312e2c3d29bSTommi Virtanen goto out; 313e2c3d29bSTommi Virtanen } 314e2c3d29bSTommi Virtanen 3154b2a58abSTommi Virtanen ckey = ukey->payload.data; 3164b2a58abSTommi Virtanen err = ceph_crypto_key_clone(dst, ckey); 317e2c3d29bSTommi Virtanen if (err) 318e2c3d29bSTommi Virtanen goto out_key; 319e2c3d29bSTommi Virtanen /* pass through, err is 0 */ 320e2c3d29bSTommi Virtanen 321e2c3d29bSTommi Virtanen out_key: 322e2c3d29bSTommi Virtanen key_put(ukey); 323e2c3d29bSTommi Virtanen out: 324e2c3d29bSTommi Virtanen return err; 325e2c3d29bSTommi Virtanen } 326e2c3d29bSTommi Virtanen 327ee57741cSAlex Elder struct ceph_options * 328ee57741cSAlex Elder ceph_parse_options(char *options, const char *dev_name, 329ee57741cSAlex Elder const char *dev_name_end, 3303d14c5d2SYehuda Sadeh int (*parse_extra_token)(char *c, void *private), 3313d14c5d2SYehuda Sadeh void *private) 3323d14c5d2SYehuda Sadeh { 3333d14c5d2SYehuda Sadeh struct ceph_options *opt; 3343d14c5d2SYehuda Sadeh const char *c; 3353d14c5d2SYehuda Sadeh int err = -ENOMEM; 3363d14c5d2SYehuda Sadeh substring_t argstr[MAX_OPT_ARGS]; 3373d14c5d2SYehuda Sadeh 338eea553c2SEric W. Biederman if (current->nsproxy->net_ns != &init_net) 339eea553c2SEric W. Biederman return ERR_PTR(-EINVAL); 340eea553c2SEric W. Biederman 3413d14c5d2SYehuda Sadeh opt = kzalloc(sizeof(*opt), GFP_KERNEL); 3423d14c5d2SYehuda Sadeh if (!opt) 343ee57741cSAlex Elder return ERR_PTR(-ENOMEM); 3443d14c5d2SYehuda Sadeh opt->mon_addr = kcalloc(CEPH_MAX_MON, sizeof(*opt->mon_addr), 3453d14c5d2SYehuda Sadeh GFP_KERNEL); 3463d14c5d2SYehuda Sadeh if (!opt->mon_addr) 3473d14c5d2SYehuda Sadeh goto out; 3483d14c5d2SYehuda Sadeh 3493d14c5d2SYehuda Sadeh dout("parse_options %p options '%s' dev_name '%s'\n", opt, options, 3503d14c5d2SYehuda Sadeh dev_name); 3513d14c5d2SYehuda Sadeh 3523d14c5d2SYehuda Sadeh /* start with defaults */ 3533d14c5d2SYehuda Sadeh opt->flags = CEPH_OPT_DEFAULT; 3543d14c5d2SYehuda Sadeh opt->osd_keepalive_timeout = CEPH_OSD_KEEPALIVE_DEFAULT; 355a319bf56SIlya Dryomov opt->mount_timeout = CEPH_MOUNT_TIMEOUT_DEFAULT; 356a319bf56SIlya Dryomov opt->osd_idle_ttl = CEPH_OSD_IDLE_TTL_DEFAULT; 3573d14c5d2SYehuda Sadeh 3583d14c5d2SYehuda Sadeh /* get mon ip(s) */ 3593d14c5d2SYehuda Sadeh /* ip1[:port1][,ip2[:port2]...] */ 3603d14c5d2SYehuda Sadeh err = ceph_parse_ips(dev_name, dev_name_end, opt->mon_addr, 3613d14c5d2SYehuda Sadeh CEPH_MAX_MON, &opt->num_mon); 3623d14c5d2SYehuda Sadeh if (err < 0) 3633d14c5d2SYehuda Sadeh goto out; 3643d14c5d2SYehuda Sadeh 3653d14c5d2SYehuda Sadeh /* parse mount options */ 3663d14c5d2SYehuda Sadeh while ((c = strsep(&options, ",")) != NULL) { 3673d14c5d2SYehuda Sadeh int token, intval, ret; 3683d14c5d2SYehuda Sadeh if (!*c) 3693d14c5d2SYehuda Sadeh continue; 3703d14c5d2SYehuda Sadeh err = -EINVAL; 3713d14c5d2SYehuda Sadeh token = match_token((char *)c, opt_tokens, argstr); 372010e3b48SYehuda Sadeh if (token < 0 && parse_extra_token) { 3733d14c5d2SYehuda Sadeh /* extra? */ 3743d14c5d2SYehuda Sadeh err = parse_extra_token((char *)c, private); 3753d14c5d2SYehuda Sadeh if (err < 0) { 3763d14c5d2SYehuda Sadeh pr_err("bad option at '%s'\n", c); 3773d14c5d2SYehuda Sadeh goto out; 3783d14c5d2SYehuda Sadeh } 3793d14c5d2SYehuda Sadeh continue; 3803d14c5d2SYehuda Sadeh } 3813d14c5d2SYehuda Sadeh if (token < Opt_last_int) { 3823d14c5d2SYehuda Sadeh ret = match_int(&argstr[0], &intval); 3833d14c5d2SYehuda Sadeh if (ret < 0) { 3843d14c5d2SYehuda Sadeh pr_err("bad mount option arg (not int) " 3853d14c5d2SYehuda Sadeh "at '%s'\n", c); 3863d14c5d2SYehuda Sadeh continue; 3873d14c5d2SYehuda Sadeh } 3883d14c5d2SYehuda Sadeh dout("got int token %d val %d\n", token, intval); 3893d14c5d2SYehuda Sadeh } else if (token > Opt_last_int && token < Opt_last_string) { 3903d14c5d2SYehuda Sadeh dout("got string token %d val %s\n", token, 3913d14c5d2SYehuda Sadeh argstr[0].from); 3923d14c5d2SYehuda Sadeh } else { 3933d14c5d2SYehuda Sadeh dout("got token %d\n", token); 3943d14c5d2SYehuda Sadeh } 3953d14c5d2SYehuda Sadeh switch (token) { 3963d14c5d2SYehuda Sadeh case Opt_ip: 3973d14c5d2SYehuda Sadeh err = ceph_parse_ips(argstr[0].from, 3983d14c5d2SYehuda Sadeh argstr[0].to, 3993d14c5d2SYehuda Sadeh &opt->my_addr, 4003d14c5d2SYehuda Sadeh 1, NULL); 4013d14c5d2SYehuda Sadeh if (err < 0) 4023d14c5d2SYehuda Sadeh goto out; 4033d14c5d2SYehuda Sadeh opt->flags |= CEPH_OPT_MYIP; 4043d14c5d2SYehuda Sadeh break; 4053d14c5d2SYehuda Sadeh 4063d14c5d2SYehuda Sadeh case Opt_fsid: 4073d14c5d2SYehuda Sadeh err = parse_fsid(argstr[0].from, &opt->fsid); 4083d14c5d2SYehuda Sadeh if (err == 0) 4093d14c5d2SYehuda Sadeh opt->flags |= CEPH_OPT_FSID; 4103d14c5d2SYehuda Sadeh break; 4113d14c5d2SYehuda Sadeh case Opt_name: 4123d14c5d2SYehuda Sadeh opt->name = kstrndup(argstr[0].from, 4133d14c5d2SYehuda Sadeh argstr[0].to-argstr[0].from, 4143d14c5d2SYehuda Sadeh GFP_KERNEL); 4153d14c5d2SYehuda Sadeh break; 4163d14c5d2SYehuda Sadeh case Opt_secret: 4178323c3aaSTommi Virtanen opt->key = kzalloc(sizeof(*opt->key), GFP_KERNEL); 4188323c3aaSTommi Virtanen if (!opt->key) { 4198323c3aaSTommi Virtanen err = -ENOMEM; 4208323c3aaSTommi Virtanen goto out; 4218323c3aaSTommi Virtanen } 4228323c3aaSTommi Virtanen err = ceph_crypto_key_unarmor(opt->key, argstr[0].from); 4238323c3aaSTommi Virtanen if (err < 0) 4248323c3aaSTommi Virtanen goto out; 4253d14c5d2SYehuda Sadeh break; 426e2c3d29bSTommi Virtanen case Opt_key: 427e2c3d29bSTommi Virtanen opt->key = kzalloc(sizeof(*opt->key), GFP_KERNEL); 428e2c3d29bSTommi Virtanen if (!opt->key) { 429e2c3d29bSTommi Virtanen err = -ENOMEM; 430e2c3d29bSTommi Virtanen goto out; 431e2c3d29bSTommi Virtanen } 432e2c3d29bSTommi Virtanen err = get_secret(opt->key, argstr[0].from); 433e2c3d29bSTommi Virtanen if (err < 0) 434e2c3d29bSTommi Virtanen goto out; 435e2c3d29bSTommi Virtanen break; 4363d14c5d2SYehuda Sadeh 4373d14c5d2SYehuda Sadeh /* misc */ 4383d14c5d2SYehuda Sadeh case Opt_osdtimeout: 439b9a67899SJoe Perches pr_warn("ignoring deprecated osdtimeout option\n"); 4403d14c5d2SYehuda Sadeh break; 4413d14c5d2SYehuda Sadeh case Opt_osdkeepalivetimeout: 442a319bf56SIlya Dryomov /* 0 isn't well defined right now, reject it */ 443a319bf56SIlya Dryomov if (intval < 1 || intval > INT_MAX / 1000) { 444a319bf56SIlya Dryomov pr_err("osdkeepalive out of range\n"); 445a319bf56SIlya Dryomov err = -EINVAL; 446a319bf56SIlya Dryomov goto out; 447a319bf56SIlya Dryomov } 448a319bf56SIlya Dryomov opt->osd_keepalive_timeout = 449a319bf56SIlya Dryomov msecs_to_jiffies(intval * 1000); 4503d14c5d2SYehuda Sadeh break; 4513d14c5d2SYehuda Sadeh case Opt_osd_idle_ttl: 452a319bf56SIlya Dryomov /* 0 isn't well defined right now, reject it */ 453a319bf56SIlya Dryomov if (intval < 1 || intval > INT_MAX / 1000) { 454a319bf56SIlya Dryomov pr_err("osd_idle_ttl out of range\n"); 455a319bf56SIlya Dryomov err = -EINVAL; 456a319bf56SIlya Dryomov goto out; 457a319bf56SIlya Dryomov } 458a319bf56SIlya Dryomov opt->osd_idle_ttl = msecs_to_jiffies(intval * 1000); 4593d14c5d2SYehuda Sadeh break; 4603d14c5d2SYehuda Sadeh case Opt_mount_timeout: 461a319bf56SIlya Dryomov /* 0 is "wait forever" (i.e. infinite timeout) */ 462a319bf56SIlya Dryomov if (intval < 0 || intval > INT_MAX / 1000) { 463a319bf56SIlya Dryomov pr_err("mount_timeout out of range\n"); 464a319bf56SIlya Dryomov err = -EINVAL; 465a319bf56SIlya Dryomov goto out; 466a319bf56SIlya Dryomov } 467a319bf56SIlya Dryomov opt->mount_timeout = msecs_to_jiffies(intval * 1000); 4683d14c5d2SYehuda Sadeh break; 4693d14c5d2SYehuda Sadeh 470cffaba15SAlex Elder case Opt_share: 471cffaba15SAlex Elder opt->flags &= ~CEPH_OPT_NOSHARE; 472cffaba15SAlex Elder break; 4733d14c5d2SYehuda Sadeh case Opt_noshare: 4743d14c5d2SYehuda Sadeh opt->flags |= CEPH_OPT_NOSHARE; 4753d14c5d2SYehuda Sadeh break; 4763d14c5d2SYehuda Sadeh 477cffaba15SAlex Elder case Opt_crc: 478cffaba15SAlex Elder opt->flags &= ~CEPH_OPT_NOCRC; 479cffaba15SAlex Elder break; 4803d14c5d2SYehuda Sadeh case Opt_nocrc: 4813d14c5d2SYehuda Sadeh opt->flags |= CEPH_OPT_NOCRC; 4823d14c5d2SYehuda Sadeh break; 483ba988f87SChaitanya Huilgol 484a3fc9800SYan, Zheng case Opt_cephx_require_signatures: 485a3fc9800SYan, Zheng opt->flags &= ~CEPH_OPT_NOMSGAUTH; 486a3fc9800SYan, Zheng break; 487a3fc9800SYan, Zheng case Opt_nocephx_require_signatures: 488a3fc9800SYan, Zheng opt->flags |= CEPH_OPT_NOMSGAUTH; 489a3fc9800SYan, Zheng break; 4903d14c5d2SYehuda Sadeh 491ba988f87SChaitanya Huilgol case Opt_tcp_nodelay: 492ba988f87SChaitanya Huilgol opt->flags |= CEPH_OPT_TCP_NODELAY; 493ba988f87SChaitanya Huilgol break; 494ba988f87SChaitanya Huilgol case Opt_notcp_nodelay: 495ba988f87SChaitanya Huilgol opt->flags &= ~CEPH_OPT_TCP_NODELAY; 496ba988f87SChaitanya Huilgol break; 497ba988f87SChaitanya Huilgol 4983d14c5d2SYehuda Sadeh default: 4993d14c5d2SYehuda Sadeh BUG_ON(token); 5003d14c5d2SYehuda Sadeh } 5013d14c5d2SYehuda Sadeh } 5023d14c5d2SYehuda Sadeh 5033d14c5d2SYehuda Sadeh /* success */ 504ee57741cSAlex Elder return opt; 5053d14c5d2SYehuda Sadeh 5063d14c5d2SYehuda Sadeh out: 5073d14c5d2SYehuda Sadeh ceph_destroy_options(opt); 508ee57741cSAlex Elder return ERR_PTR(err); 5093d14c5d2SYehuda Sadeh } 5103d14c5d2SYehuda Sadeh EXPORT_SYMBOL(ceph_parse_options); 5113d14c5d2SYehuda Sadeh 512ff40f9aeSIlya Dryomov int ceph_print_client_options(struct seq_file *m, struct ceph_client *client) 513ff40f9aeSIlya Dryomov { 514ff40f9aeSIlya Dryomov struct ceph_options *opt = client->options; 515ff40f9aeSIlya Dryomov size_t pos = m->count; 516ff40f9aeSIlya Dryomov 517ff40f9aeSIlya Dryomov if (opt->name) 518ff40f9aeSIlya Dryomov seq_printf(m, "name=%s,", opt->name); 519ff40f9aeSIlya Dryomov if (opt->key) 520ff40f9aeSIlya Dryomov seq_puts(m, "secret=<hidden>,"); 521ff40f9aeSIlya Dryomov 522ff40f9aeSIlya Dryomov if (opt->flags & CEPH_OPT_FSID) 523ff40f9aeSIlya Dryomov seq_printf(m, "fsid=%pU,", &opt->fsid); 524ff40f9aeSIlya Dryomov if (opt->flags & CEPH_OPT_NOSHARE) 525ff40f9aeSIlya Dryomov seq_puts(m, "noshare,"); 526ff40f9aeSIlya Dryomov if (opt->flags & CEPH_OPT_NOCRC) 527ff40f9aeSIlya Dryomov seq_puts(m, "nocrc,"); 528ff40f9aeSIlya Dryomov if (opt->flags & CEPH_OPT_NOMSGAUTH) 529ff40f9aeSIlya Dryomov seq_puts(m, "nocephx_require_signatures,"); 530ff40f9aeSIlya Dryomov if ((opt->flags & CEPH_OPT_TCP_NODELAY) == 0) 531ff40f9aeSIlya Dryomov seq_puts(m, "notcp_nodelay,"); 532ff40f9aeSIlya Dryomov 533ff40f9aeSIlya Dryomov if (opt->mount_timeout != CEPH_MOUNT_TIMEOUT_DEFAULT) 534a319bf56SIlya Dryomov seq_printf(m, "mount_timeout=%d,", 535a319bf56SIlya Dryomov jiffies_to_msecs(opt->mount_timeout) / 1000); 536ff40f9aeSIlya Dryomov if (opt->osd_idle_ttl != CEPH_OSD_IDLE_TTL_DEFAULT) 537a319bf56SIlya Dryomov seq_printf(m, "osd_idle_ttl=%d,", 538a319bf56SIlya Dryomov jiffies_to_msecs(opt->osd_idle_ttl) / 1000); 539ff40f9aeSIlya Dryomov if (opt->osd_keepalive_timeout != CEPH_OSD_KEEPALIVE_DEFAULT) 540ff40f9aeSIlya Dryomov seq_printf(m, "osdkeepalivetimeout=%d,", 541a319bf56SIlya Dryomov jiffies_to_msecs(opt->osd_keepalive_timeout) / 1000); 542ff40f9aeSIlya Dryomov 543ff40f9aeSIlya Dryomov /* drop redundant comma */ 544ff40f9aeSIlya Dryomov if (m->count != pos) 545ff40f9aeSIlya Dryomov m->count--; 546ff40f9aeSIlya Dryomov 547ff40f9aeSIlya Dryomov return 0; 548ff40f9aeSIlya Dryomov } 549ff40f9aeSIlya Dryomov EXPORT_SYMBOL(ceph_print_client_options); 550ff40f9aeSIlya Dryomov 5513d14c5d2SYehuda Sadeh u64 ceph_client_id(struct ceph_client *client) 5523d14c5d2SYehuda Sadeh { 5533d14c5d2SYehuda Sadeh return client->monc.auth->global_id; 5543d14c5d2SYehuda Sadeh } 5553d14c5d2SYehuda Sadeh EXPORT_SYMBOL(ceph_client_id); 5563d14c5d2SYehuda Sadeh 5573d14c5d2SYehuda Sadeh /* 5583d14c5d2SYehuda Sadeh * create a fresh client instance 5593d14c5d2SYehuda Sadeh */ 5606ab00d46SSage Weil struct ceph_client *ceph_create_client(struct ceph_options *opt, void *private, 56112b4629aSIlya Dryomov u64 supported_features, 56212b4629aSIlya Dryomov u64 required_features) 5633d14c5d2SYehuda Sadeh { 5643d14c5d2SYehuda Sadeh struct ceph_client *client; 5656ab00d46SSage Weil struct ceph_entity_addr *myaddr = NULL; 5663d14c5d2SYehuda Sadeh int err = -ENOMEM; 5673d14c5d2SYehuda Sadeh 5683d14c5d2SYehuda Sadeh client = kzalloc(sizeof(*client), GFP_KERNEL); 5693d14c5d2SYehuda Sadeh if (client == NULL) 5703d14c5d2SYehuda Sadeh return ERR_PTR(-ENOMEM); 5713d14c5d2SYehuda Sadeh 5723d14c5d2SYehuda Sadeh client->private = private; 5733d14c5d2SYehuda Sadeh client->options = opt; 5743d14c5d2SYehuda Sadeh 5753d14c5d2SYehuda Sadeh mutex_init(&client->mount_mutex); 5763d14c5d2SYehuda Sadeh init_waitqueue_head(&client->auth_wq); 5773d14c5d2SYehuda Sadeh client->auth_err = 0; 5783d14c5d2SYehuda Sadeh 579a3fc9800SYan, Zheng if (!ceph_test_opt(client, NOMSGAUTH)) 580a3fc9800SYan, Zheng required_features |= CEPH_FEATURE_MSG_AUTH; 581a3fc9800SYan, Zheng 5823d14c5d2SYehuda Sadeh client->extra_mon_dispatch = NULL; 5831fe60e51SSage Weil client->supported_features = CEPH_FEATURES_SUPPORTED_DEFAULT | 5846ab00d46SSage Weil supported_features; 5851fe60e51SSage Weil client->required_features = CEPH_FEATURES_REQUIRED_DEFAULT | 5866ab00d46SSage Weil required_features; 5873d14c5d2SYehuda Sadeh 5886ab00d46SSage Weil /* msgr */ 5896ab00d46SSage Weil if (ceph_test_opt(client, MYIP)) 5906ab00d46SSage Weil myaddr = &client->options->my_addr; 591ba988f87SChaitanya Huilgol 59215d9882cSAlex Elder ceph_messenger_init(&client->msgr, myaddr, 5936ab00d46SSage Weil client->supported_features, 59415d9882cSAlex Elder client->required_features, 595ba988f87SChaitanya Huilgol ceph_test_opt(client, NOCRC), 596ba988f87SChaitanya Huilgol ceph_test_opt(client, TCP_NODELAY)); 5973d14c5d2SYehuda Sadeh 5983d14c5d2SYehuda Sadeh /* subsystems */ 5993d14c5d2SYehuda Sadeh err = ceph_monc_init(&client->monc, client); 6003d14c5d2SYehuda Sadeh if (err < 0) 60115d9882cSAlex Elder goto fail; 6023d14c5d2SYehuda Sadeh err = ceph_osdc_init(&client->osdc, client); 6033d14c5d2SYehuda Sadeh if (err < 0) 6043d14c5d2SYehuda Sadeh goto fail_monc; 6053d14c5d2SYehuda Sadeh 6063d14c5d2SYehuda Sadeh return client; 6073d14c5d2SYehuda Sadeh 6083d14c5d2SYehuda Sadeh fail_monc: 6093d14c5d2SYehuda Sadeh ceph_monc_stop(&client->monc); 6103d14c5d2SYehuda Sadeh fail: 6113d14c5d2SYehuda Sadeh kfree(client); 6123d14c5d2SYehuda Sadeh return ERR_PTR(err); 6133d14c5d2SYehuda Sadeh } 6143d14c5d2SYehuda Sadeh EXPORT_SYMBOL(ceph_create_client); 6153d14c5d2SYehuda Sadeh 6163d14c5d2SYehuda Sadeh void ceph_destroy_client(struct ceph_client *client) 6173d14c5d2SYehuda Sadeh { 6183d14c5d2SYehuda Sadeh dout("destroy_client %p\n", client); 6193d14c5d2SYehuda Sadeh 620a2a32584SGuanjun He atomic_set(&client->msgr.stopping, 1); 621a2a32584SGuanjun He 6223d14c5d2SYehuda Sadeh /* unmount */ 6233d14c5d2SYehuda Sadeh ceph_osdc_stop(&client->osdc); 6243d14c5d2SYehuda Sadeh 6253d14c5d2SYehuda Sadeh ceph_monc_stop(&client->monc); 6263d14c5d2SYehuda Sadeh 6273d14c5d2SYehuda Sadeh ceph_debugfs_client_cleanup(client); 6283d14c5d2SYehuda Sadeh 6293d14c5d2SYehuda Sadeh ceph_destroy_options(client->options); 6303d14c5d2SYehuda Sadeh 6313d14c5d2SYehuda Sadeh kfree(client); 6323d14c5d2SYehuda Sadeh dout("destroy_client %p done\n", client); 6333d14c5d2SYehuda Sadeh } 6343d14c5d2SYehuda Sadeh EXPORT_SYMBOL(ceph_destroy_client); 6353d14c5d2SYehuda Sadeh 6363d14c5d2SYehuda Sadeh /* 6373d14c5d2SYehuda Sadeh * true if we have the mon map (and have thus joined the cluster) 6383d14c5d2SYehuda Sadeh */ 6393d14c5d2SYehuda Sadeh static int have_mon_and_osd_map(struct ceph_client *client) 6403d14c5d2SYehuda Sadeh { 6413d14c5d2SYehuda Sadeh return client->monc.monmap && client->monc.monmap->epoch && 6423d14c5d2SYehuda Sadeh client->osdc.osdmap && client->osdc.osdmap->epoch; 6433d14c5d2SYehuda Sadeh } 6443d14c5d2SYehuda Sadeh 6453d14c5d2SYehuda Sadeh /* 6463d14c5d2SYehuda Sadeh * mount: join the ceph cluster, and open root directory. 6473d14c5d2SYehuda Sadeh */ 6483d14c5d2SYehuda Sadeh int __ceph_open_session(struct ceph_client *client, unsigned long started) 6493d14c5d2SYehuda Sadeh { 650a319bf56SIlya Dryomov unsigned long timeout = client->options->mount_timeout; 651*216639ddSIlya Dryomov long err; 6523d14c5d2SYehuda Sadeh 6533d14c5d2SYehuda Sadeh /* open session, and wait for mon and osd maps */ 6543d14c5d2SYehuda Sadeh err = ceph_monc_open_session(&client->monc); 6553d14c5d2SYehuda Sadeh if (err < 0) 6563d14c5d2SYehuda Sadeh return err; 6573d14c5d2SYehuda Sadeh 6583d14c5d2SYehuda Sadeh while (!have_mon_and_osd_map(client)) { 6593d14c5d2SYehuda Sadeh if (timeout && time_after_eq(jiffies, started + timeout)) 660*216639ddSIlya Dryomov return -ETIMEDOUT; 6613d14c5d2SYehuda Sadeh 6623d14c5d2SYehuda Sadeh /* wait */ 6633d14c5d2SYehuda Sadeh dout("mount waiting for mon_map\n"); 6643d14c5d2SYehuda Sadeh err = wait_event_interruptible_timeout(client->auth_wq, 6653d14c5d2SYehuda Sadeh have_mon_and_osd_map(client) || (client->auth_err < 0), 666a319bf56SIlya Dryomov ceph_timeout_jiffies(timeout)); 667*216639ddSIlya Dryomov if (err < 0) 6683d14c5d2SYehuda Sadeh return err; 6693d14c5d2SYehuda Sadeh if (client->auth_err < 0) 6703d14c5d2SYehuda Sadeh return client->auth_err; 6713d14c5d2SYehuda Sadeh } 6723d14c5d2SYehuda Sadeh 6733d14c5d2SYehuda Sadeh return 0; 6743d14c5d2SYehuda Sadeh } 6753d14c5d2SYehuda Sadeh EXPORT_SYMBOL(__ceph_open_session); 6763d14c5d2SYehuda Sadeh 6773d14c5d2SYehuda Sadeh 6783d14c5d2SYehuda Sadeh int ceph_open_session(struct ceph_client *client) 6793d14c5d2SYehuda Sadeh { 6803d14c5d2SYehuda Sadeh int ret; 6813d14c5d2SYehuda Sadeh unsigned long started = jiffies; /* note the start time */ 6823d14c5d2SYehuda Sadeh 6833d14c5d2SYehuda Sadeh dout("open_session start\n"); 6843d14c5d2SYehuda Sadeh mutex_lock(&client->mount_mutex); 6853d14c5d2SYehuda Sadeh 6863d14c5d2SYehuda Sadeh ret = __ceph_open_session(client, started); 6873d14c5d2SYehuda Sadeh 6883d14c5d2SYehuda Sadeh mutex_unlock(&client->mount_mutex); 6893d14c5d2SYehuda Sadeh return ret; 6903d14c5d2SYehuda Sadeh } 6913d14c5d2SYehuda Sadeh EXPORT_SYMBOL(ceph_open_session); 6923d14c5d2SYehuda Sadeh 6933d14c5d2SYehuda Sadeh 6943d14c5d2SYehuda Sadeh static int __init init_ceph_lib(void) 6953d14c5d2SYehuda Sadeh { 6963d14c5d2SYehuda Sadeh int ret = 0; 6973d14c5d2SYehuda Sadeh 6983d14c5d2SYehuda Sadeh ret = ceph_debugfs_init(); 6993d14c5d2SYehuda Sadeh if (ret < 0) 7003d14c5d2SYehuda Sadeh goto out; 7013d14c5d2SYehuda Sadeh 7024b2a58abSTommi Virtanen ret = ceph_crypto_init(); 7033d14c5d2SYehuda Sadeh if (ret < 0) 7043d14c5d2SYehuda Sadeh goto out_debugfs; 7053d14c5d2SYehuda Sadeh 7064b2a58abSTommi Virtanen ret = ceph_msgr_init(); 7074b2a58abSTommi Virtanen if (ret < 0) 7084b2a58abSTommi Virtanen goto out_crypto; 7094b2a58abSTommi Virtanen 7105522ae0bSAlex Elder ret = ceph_osdc_setup(); 7115522ae0bSAlex Elder if (ret < 0) 7125522ae0bSAlex Elder goto out_msgr; 7135522ae0bSAlex Elder 7144f6a7e5eSSage Weil pr_info("loaded (mon/osd proto %d/%d)\n", 7154f6a7e5eSSage Weil CEPH_MONC_PROTOCOL, CEPH_OSDC_PROTOCOL); 7163d14c5d2SYehuda Sadeh 7173d14c5d2SYehuda Sadeh return 0; 7183d14c5d2SYehuda Sadeh 7195522ae0bSAlex Elder out_msgr: 7205522ae0bSAlex Elder ceph_msgr_exit(); 7214b2a58abSTommi Virtanen out_crypto: 7224b2a58abSTommi Virtanen ceph_crypto_shutdown(); 7233d14c5d2SYehuda Sadeh out_debugfs: 7243d14c5d2SYehuda Sadeh ceph_debugfs_cleanup(); 7253d14c5d2SYehuda Sadeh out: 7263d14c5d2SYehuda Sadeh return ret; 7273d14c5d2SYehuda Sadeh } 7283d14c5d2SYehuda Sadeh 7293d14c5d2SYehuda Sadeh static void __exit exit_ceph_lib(void) 7303d14c5d2SYehuda Sadeh { 7313d14c5d2SYehuda Sadeh dout("exit_ceph_lib\n"); 7325522ae0bSAlex Elder ceph_osdc_cleanup(); 7333d14c5d2SYehuda Sadeh ceph_msgr_exit(); 7344b2a58abSTommi Virtanen ceph_crypto_shutdown(); 7353d14c5d2SYehuda Sadeh ceph_debugfs_cleanup(); 7363d14c5d2SYehuda Sadeh } 7373d14c5d2SYehuda Sadeh 7383d14c5d2SYehuda Sadeh module_init(init_ceph_lib); 7393d14c5d2SYehuda Sadeh module_exit(exit_ceph_lib); 7403d14c5d2SYehuda Sadeh 7413d14c5d2SYehuda Sadeh MODULE_AUTHOR("Sage Weil <sage@newdream.net>"); 7423d14c5d2SYehuda Sadeh MODULE_AUTHOR("Yehuda Sadeh <yehuda@hq.newdream.net>"); 7433d14c5d2SYehuda Sadeh MODULE_AUTHOR("Patience Warnick <patience@newdream.net>"); 7443d14c5d2SYehuda Sadeh MODULE_DESCRIPTION("Ceph filesystem for Linux"); 7453d14c5d2SYehuda Sadeh MODULE_LICENSE("GPL"); 746