109c434b8SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 23d14c5d2SYehuda Sadeh 33d14c5d2SYehuda Sadeh #include <linux/ceph/ceph_debug.h> 43d14c5d2SYehuda Sadeh #include <linux/backing-dev.h> 53d14c5d2SYehuda Sadeh #include <linux/ctype.h> 63d14c5d2SYehuda Sadeh #include <linux/fs.h> 73d14c5d2SYehuda Sadeh #include <linux/inet.h> 83d14c5d2SYehuda Sadeh #include <linux/in6.h> 9e2c3d29bSTommi Virtanen #include <linux/key.h> 104b2a58abSTommi Virtanen #include <keys/ceph-type.h> 113d14c5d2SYehuda Sadeh #include <linux/module.h> 123d14c5d2SYehuda Sadeh #include <linux/mount.h> 13757856d2SIlya Dryomov #include <linux/nsproxy.h> 143d14c5d2SYehuda Sadeh #include <linux/parser.h> 153d14c5d2SYehuda Sadeh #include <linux/sched.h> 163d14c5d2SYehuda Sadeh #include <linux/seq_file.h> 173d14c5d2SYehuda Sadeh #include <linux/slab.h> 183d14c5d2SYehuda Sadeh #include <linux/statfs.h> 193d14c5d2SYehuda Sadeh #include <linux/string.h> 20eeb0bed5SIlya Dryomov #include <linux/vmalloc.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 49d6a3408aSIlya Dryomov static int param_get_supported_features(char *buffer, 50d6a3408aSIlya Dryomov const struct kernel_param *kp) 51d6a3408aSIlya Dryomov { 52d6a3408aSIlya Dryomov return sprintf(buffer, "0x%llx", CEPH_FEATURES_SUPPORTED_DEFAULT); 53d6a3408aSIlya Dryomov } 54d6a3408aSIlya Dryomov static const struct kernel_param_ops param_ops_supported_features = { 55d6a3408aSIlya Dryomov .get = param_get_supported_features, 56d6a3408aSIlya Dryomov }; 57d6a3408aSIlya Dryomov module_param_cb(supported_features, ¶m_ops_supported_features, NULL, 58d6444062SJoe Perches 0444); 59d6a3408aSIlya Dryomov 603d14c5d2SYehuda Sadeh const char *ceph_msg_type_name(int type) 613d14c5d2SYehuda Sadeh { 623d14c5d2SYehuda Sadeh switch (type) { 633d14c5d2SYehuda Sadeh case CEPH_MSG_SHUTDOWN: return "shutdown"; 643d14c5d2SYehuda Sadeh case CEPH_MSG_PING: return "ping"; 653d14c5d2SYehuda Sadeh case CEPH_MSG_AUTH: return "auth"; 663d14c5d2SYehuda Sadeh case CEPH_MSG_AUTH_REPLY: return "auth_reply"; 673d14c5d2SYehuda Sadeh case CEPH_MSG_MON_MAP: return "mon_map"; 683d14c5d2SYehuda Sadeh case CEPH_MSG_MON_GET_MAP: return "mon_get_map"; 693d14c5d2SYehuda Sadeh case CEPH_MSG_MON_SUBSCRIBE: return "mon_subscribe"; 703d14c5d2SYehuda Sadeh case CEPH_MSG_MON_SUBSCRIBE_ACK: return "mon_subscribe_ack"; 713d14c5d2SYehuda Sadeh case CEPH_MSG_STATFS: return "statfs"; 723d14c5d2SYehuda Sadeh case CEPH_MSG_STATFS_REPLY: return "statfs_reply"; 73513a8243SIlya Dryomov case CEPH_MSG_MON_GET_VERSION: return "mon_get_version"; 74513a8243SIlya Dryomov case CEPH_MSG_MON_GET_VERSION_REPLY: return "mon_get_version_reply"; 753d14c5d2SYehuda Sadeh case CEPH_MSG_MDS_MAP: return "mds_map"; 76f2f87877SChengguang Xu case CEPH_MSG_FS_MAP_USER: return "fs_map_user"; 773d14c5d2SYehuda Sadeh case CEPH_MSG_CLIENT_SESSION: return "client_session"; 783d14c5d2SYehuda Sadeh case CEPH_MSG_CLIENT_RECONNECT: return "client_reconnect"; 793d14c5d2SYehuda Sadeh case CEPH_MSG_CLIENT_REQUEST: return "client_request"; 803d14c5d2SYehuda Sadeh case CEPH_MSG_CLIENT_REQUEST_FORWARD: return "client_request_forward"; 813d14c5d2SYehuda Sadeh case CEPH_MSG_CLIENT_REPLY: return "client_reply"; 823d14c5d2SYehuda Sadeh case CEPH_MSG_CLIENT_CAPS: return "client_caps"; 833d14c5d2SYehuda Sadeh case CEPH_MSG_CLIENT_CAPRELEASE: return "client_cap_release"; 84fb18a575SLuis Henriques case CEPH_MSG_CLIENT_QUOTA: return "client_quota"; 853d14c5d2SYehuda Sadeh case CEPH_MSG_CLIENT_SNAP: return "client_snap"; 863d14c5d2SYehuda Sadeh case CEPH_MSG_CLIENT_LEASE: return "client_lease"; 87f2f87877SChengguang Xu case CEPH_MSG_POOLOP_REPLY: return "poolop_reply"; 88f2f87877SChengguang Xu case CEPH_MSG_POOLOP: return "poolop"; 89f2f87877SChengguang Xu case CEPH_MSG_MON_COMMAND: return "mon_command"; 90f2f87877SChengguang Xu case CEPH_MSG_MON_COMMAND_ACK: return "mon_command_ack"; 913d14c5d2SYehuda Sadeh case CEPH_MSG_OSD_MAP: return "osd_map"; 923d14c5d2SYehuda Sadeh case CEPH_MSG_OSD_OP: return "osd_op"; 933d14c5d2SYehuda Sadeh case CEPH_MSG_OSD_OPREPLY: return "osd_opreply"; 94a40c4f10SYehuda Sadeh case CEPH_MSG_WATCH_NOTIFY: return "watch_notify"; 95a02a946dSIlya Dryomov case CEPH_MSG_OSD_BACKOFF: return "osd_backoff"; 963d14c5d2SYehuda Sadeh default: return "unknown"; 973d14c5d2SYehuda Sadeh } 983d14c5d2SYehuda Sadeh } 993d14c5d2SYehuda Sadeh EXPORT_SYMBOL(ceph_msg_type_name); 1003d14c5d2SYehuda Sadeh 1013d14c5d2SYehuda Sadeh /* 1023d14c5d2SYehuda Sadeh * Initially learn our fsid, or verify an fsid matches. 1033d14c5d2SYehuda Sadeh */ 1043d14c5d2SYehuda Sadeh int ceph_check_fsid(struct ceph_client *client, struct ceph_fsid *fsid) 1053d14c5d2SYehuda Sadeh { 1063d14c5d2SYehuda Sadeh if (client->have_fsid) { 1073d14c5d2SYehuda Sadeh if (ceph_fsid_compare(&client->fsid, fsid)) { 1083d14c5d2SYehuda Sadeh pr_err("bad fsid, had %pU got %pU", 1093d14c5d2SYehuda Sadeh &client->fsid, fsid); 1103d14c5d2SYehuda Sadeh return -1; 1113d14c5d2SYehuda Sadeh } 1123d14c5d2SYehuda Sadeh } else { 1133d14c5d2SYehuda Sadeh memcpy(&client->fsid, fsid, sizeof(*fsid)); 1143d14c5d2SYehuda Sadeh } 1153d14c5d2SYehuda Sadeh return 0; 1163d14c5d2SYehuda Sadeh } 1173d14c5d2SYehuda Sadeh EXPORT_SYMBOL(ceph_check_fsid); 1183d14c5d2SYehuda Sadeh 1193d14c5d2SYehuda Sadeh static int strcmp_null(const char *s1, const char *s2) 1203d14c5d2SYehuda Sadeh { 1213d14c5d2SYehuda Sadeh if (!s1 && !s2) 1223d14c5d2SYehuda Sadeh return 0; 1233d14c5d2SYehuda Sadeh if (s1 && !s2) 1243d14c5d2SYehuda Sadeh return -1; 1253d14c5d2SYehuda Sadeh if (!s1 && s2) 1263d14c5d2SYehuda Sadeh return 1; 1273d14c5d2SYehuda Sadeh return strcmp(s1, s2); 1283d14c5d2SYehuda Sadeh } 1293d14c5d2SYehuda Sadeh 1303d14c5d2SYehuda Sadeh int ceph_compare_options(struct ceph_options *new_opt, 1313d14c5d2SYehuda Sadeh struct ceph_client *client) 1323d14c5d2SYehuda Sadeh { 1333d14c5d2SYehuda Sadeh struct ceph_options *opt1 = new_opt; 1343d14c5d2SYehuda Sadeh struct ceph_options *opt2 = client->options; 1353d14c5d2SYehuda Sadeh int ofs = offsetof(struct ceph_options, mon_addr); 1363d14c5d2SYehuda Sadeh int i; 1373d14c5d2SYehuda Sadeh int ret; 1383d14c5d2SYehuda Sadeh 139757856d2SIlya Dryomov /* 140757856d2SIlya Dryomov * Don't bother comparing options if network namespaces don't 141757856d2SIlya Dryomov * match. 142757856d2SIlya Dryomov */ 143757856d2SIlya Dryomov if (!net_eq(current->nsproxy->net_ns, read_pnet(&client->msgr.net))) 144757856d2SIlya Dryomov return -1; 145757856d2SIlya Dryomov 1463d14c5d2SYehuda Sadeh ret = memcmp(opt1, opt2, ofs); 1473d14c5d2SYehuda Sadeh if (ret) 1483d14c5d2SYehuda Sadeh return ret; 1493d14c5d2SYehuda Sadeh 1503d14c5d2SYehuda Sadeh ret = strcmp_null(opt1->name, opt2->name); 1513d14c5d2SYehuda Sadeh if (ret) 1523d14c5d2SYehuda Sadeh return ret; 1533d14c5d2SYehuda Sadeh 1548323c3aaSTommi Virtanen if (opt1->key && !opt2->key) 1558323c3aaSTommi Virtanen return -1; 1568323c3aaSTommi Virtanen if (!opt1->key && opt2->key) 1578323c3aaSTommi Virtanen return 1; 1588323c3aaSTommi Virtanen if (opt1->key && opt2->key) { 1598323c3aaSTommi Virtanen if (opt1->key->type != opt2->key->type) 1608323c3aaSTommi Virtanen return -1; 1618323c3aaSTommi Virtanen if (opt1->key->created.tv_sec != opt2->key->created.tv_sec) 1628323c3aaSTommi Virtanen return -1; 1638323c3aaSTommi Virtanen if (opt1->key->created.tv_nsec != opt2->key->created.tv_nsec) 1648323c3aaSTommi Virtanen return -1; 1658323c3aaSTommi Virtanen if (opt1->key->len != opt2->key->len) 1668323c3aaSTommi Virtanen return -1; 1678323c3aaSTommi Virtanen if (opt1->key->key && !opt2->key->key) 1688323c3aaSTommi Virtanen return -1; 1698323c3aaSTommi Virtanen if (!opt1->key->key && opt2->key->key) 1708323c3aaSTommi Virtanen return 1; 1718323c3aaSTommi Virtanen if (opt1->key->key && opt2->key->key) { 1728323c3aaSTommi Virtanen ret = memcmp(opt1->key->key, opt2->key->key, opt1->key->len); 1733d14c5d2SYehuda Sadeh if (ret) 1743d14c5d2SYehuda Sadeh return ret; 1758323c3aaSTommi Virtanen } 1768323c3aaSTommi Virtanen } 1773d14c5d2SYehuda Sadeh 1783d14c5d2SYehuda Sadeh /* any matching mon ip implies a match */ 1793d14c5d2SYehuda Sadeh for (i = 0; i < opt1->num_mon; i++) { 1803d14c5d2SYehuda Sadeh if (ceph_monmap_contains(client->monc.monmap, 1813d14c5d2SYehuda Sadeh &opt1->mon_addr[i])) 1823d14c5d2SYehuda Sadeh return 0; 1833d14c5d2SYehuda Sadeh } 1843d14c5d2SYehuda Sadeh return -1; 1853d14c5d2SYehuda Sadeh } 1863d14c5d2SYehuda Sadeh EXPORT_SYMBOL(ceph_compare_options); 1873d14c5d2SYehuda Sadeh 188eeb0bed5SIlya Dryomov void *ceph_kvmalloc(size_t size, gfp_t flags) 189eeb0bed5SIlya Dryomov { 190eeb0bed5SIlya Dryomov if (size <= (PAGE_SIZE << PAGE_ALLOC_COSTLY_ORDER)) { 191eeb0bed5SIlya Dryomov void *ptr = kmalloc(size, flags | __GFP_NOWARN); 192eeb0bed5SIlya Dryomov if (ptr) 193eeb0bed5SIlya Dryomov return ptr; 194eeb0bed5SIlya Dryomov } 195eeb0bed5SIlya Dryomov 19619809c2dSMichal Hocko return __vmalloc(size, flags, PAGE_KERNEL); 197eeb0bed5SIlya Dryomov } 198eeb0bed5SIlya Dryomov 1993d14c5d2SYehuda Sadeh 2003d14c5d2SYehuda Sadeh static int parse_fsid(const char *str, struct ceph_fsid *fsid) 2013d14c5d2SYehuda Sadeh { 2023d14c5d2SYehuda Sadeh int i = 0; 2033d14c5d2SYehuda Sadeh char tmp[3]; 2043d14c5d2SYehuda Sadeh int err = -EINVAL; 2053d14c5d2SYehuda Sadeh int d; 2063d14c5d2SYehuda Sadeh 2073d14c5d2SYehuda Sadeh dout("parse_fsid '%s'\n", str); 2083d14c5d2SYehuda Sadeh tmp[2] = 0; 2093d14c5d2SYehuda Sadeh while (*str && i < 16) { 2103d14c5d2SYehuda Sadeh if (ispunct(*str)) { 2113d14c5d2SYehuda Sadeh str++; 2123d14c5d2SYehuda Sadeh continue; 2133d14c5d2SYehuda Sadeh } 2143d14c5d2SYehuda Sadeh if (!isxdigit(str[0]) || !isxdigit(str[1])) 2153d14c5d2SYehuda Sadeh break; 2163d14c5d2SYehuda Sadeh tmp[0] = str[0]; 2173d14c5d2SYehuda Sadeh tmp[1] = str[1]; 2183d14c5d2SYehuda Sadeh if (sscanf(tmp, "%x", &d) < 1) 2193d14c5d2SYehuda Sadeh break; 2203d14c5d2SYehuda Sadeh fsid->fsid[i] = d & 0xff; 2213d14c5d2SYehuda Sadeh i++; 2223d14c5d2SYehuda Sadeh str += 2; 2233d14c5d2SYehuda Sadeh } 2243d14c5d2SYehuda Sadeh 2253d14c5d2SYehuda Sadeh if (i == 16) 2263d14c5d2SYehuda Sadeh err = 0; 2274c069a58SChengguang Xu dout("parse_fsid ret %d got fsid %pU\n", err, fsid); 2283d14c5d2SYehuda Sadeh return err; 2293d14c5d2SYehuda Sadeh } 2303d14c5d2SYehuda Sadeh 2313d14c5d2SYehuda Sadeh /* 2323d14c5d2SYehuda Sadeh * ceph options 2333d14c5d2SYehuda Sadeh */ 2343d14c5d2SYehuda Sadeh enum { 2353d14c5d2SYehuda Sadeh Opt_osdtimeout, 2363d14c5d2SYehuda Sadeh Opt_osdkeepalivetimeout, 2373d14c5d2SYehuda Sadeh Opt_mount_timeout, 2383d14c5d2SYehuda Sadeh Opt_osd_idle_ttl, 2397cc5e38fSIlya Dryomov Opt_osd_request_timeout, 2403d14c5d2SYehuda Sadeh Opt_last_int, 2413d14c5d2SYehuda Sadeh /* int args above */ 2423d14c5d2SYehuda Sadeh Opt_fsid, 2433d14c5d2SYehuda Sadeh Opt_name, 2443d14c5d2SYehuda Sadeh Opt_secret, 245e2c3d29bSTommi Virtanen Opt_key, 2463d14c5d2SYehuda Sadeh Opt_ip, 2473d14c5d2SYehuda Sadeh Opt_last_string, 2483d14c5d2SYehuda Sadeh /* string args above */ 249cffaba15SAlex Elder Opt_share, 2503d14c5d2SYehuda Sadeh Opt_noshare, 251cffaba15SAlex Elder Opt_crc, 2523d14c5d2SYehuda Sadeh Opt_nocrc, 253a3fc9800SYan, Zheng Opt_cephx_require_signatures, 254a3fc9800SYan, Zheng Opt_nocephx_require_signatures, 255a51983e4SIlya Dryomov Opt_cephx_sign_messages, 256a51983e4SIlya Dryomov Opt_nocephx_sign_messages, 257ba988f87SChaitanya Huilgol Opt_tcp_nodelay, 258ba988f87SChaitanya Huilgol Opt_notcp_nodelay, 25902b2f549SDongsheng Yang Opt_abort_on_full, 2603d14c5d2SYehuda Sadeh }; 2613d14c5d2SYehuda Sadeh 2623d14c5d2SYehuda Sadeh static match_table_t opt_tokens = { 2633d14c5d2SYehuda Sadeh {Opt_osdtimeout, "osdtimeout=%d"}, 2643d14c5d2SYehuda Sadeh {Opt_osdkeepalivetimeout, "osdkeepalive=%d"}, 2653d14c5d2SYehuda Sadeh {Opt_mount_timeout, "mount_timeout=%d"}, 2663d14c5d2SYehuda Sadeh {Opt_osd_idle_ttl, "osd_idle_ttl=%d"}, 2677cc5e38fSIlya Dryomov {Opt_osd_request_timeout, "osd_request_timeout=%d"}, 2683d14c5d2SYehuda Sadeh /* int args above */ 2693d14c5d2SYehuda Sadeh {Opt_fsid, "fsid=%s"}, 2703d14c5d2SYehuda Sadeh {Opt_name, "name=%s"}, 2713d14c5d2SYehuda Sadeh {Opt_secret, "secret=%s"}, 272e2c3d29bSTommi Virtanen {Opt_key, "key=%s"}, 2733d14c5d2SYehuda Sadeh {Opt_ip, "ip=%s"}, 2743d14c5d2SYehuda Sadeh /* string args above */ 275cffaba15SAlex Elder {Opt_share, "share"}, 2763d14c5d2SYehuda Sadeh {Opt_noshare, "noshare"}, 277cffaba15SAlex Elder {Opt_crc, "crc"}, 2783d14c5d2SYehuda Sadeh {Opt_nocrc, "nocrc"}, 279a3fc9800SYan, Zheng {Opt_cephx_require_signatures, "cephx_require_signatures"}, 280a3fc9800SYan, Zheng {Opt_nocephx_require_signatures, "nocephx_require_signatures"}, 281a51983e4SIlya Dryomov {Opt_cephx_sign_messages, "cephx_sign_messages"}, 282a51983e4SIlya Dryomov {Opt_nocephx_sign_messages, "nocephx_sign_messages"}, 283ba988f87SChaitanya Huilgol {Opt_tcp_nodelay, "tcp_nodelay"}, 284ba988f87SChaitanya Huilgol {Opt_notcp_nodelay, "notcp_nodelay"}, 28502b2f549SDongsheng Yang {Opt_abort_on_full, "abort_on_full"}, 2863d14c5d2SYehuda Sadeh {-1, NULL} 2873d14c5d2SYehuda Sadeh }; 2883d14c5d2SYehuda Sadeh 2893d14c5d2SYehuda Sadeh void ceph_destroy_options(struct ceph_options *opt) 2903d14c5d2SYehuda Sadeh { 2913d14c5d2SYehuda Sadeh dout("destroy_options %p\n", opt); 2923d14c5d2SYehuda Sadeh kfree(opt->name); 2938323c3aaSTommi Virtanen if (opt->key) { 2948323c3aaSTommi Virtanen ceph_crypto_key_destroy(opt->key); 2958323c3aaSTommi Virtanen kfree(opt->key); 2968323c3aaSTommi Virtanen } 2971cad7893SNoah Watkins kfree(opt->mon_addr); 2983d14c5d2SYehuda Sadeh kfree(opt); 2993d14c5d2SYehuda Sadeh } 3003d14c5d2SYehuda Sadeh EXPORT_SYMBOL(ceph_destroy_options); 3013d14c5d2SYehuda Sadeh 302e2c3d29bSTommi Virtanen /* get secret from key store */ 303e2c3d29bSTommi Virtanen static int get_secret(struct ceph_crypto_key *dst, const char *name) { 304e2c3d29bSTommi Virtanen struct key *ukey; 305e2c3d29bSTommi Virtanen int key_err; 306e2c3d29bSTommi Virtanen int err = 0; 3074b2a58abSTommi Virtanen struct ceph_crypto_key *ckey; 308e2c3d29bSTommi Virtanen 3094b2a58abSTommi Virtanen ukey = request_key(&key_type_ceph, name, NULL); 310bad87216SYueHaibing if (IS_ERR(ukey)) { 311e2c3d29bSTommi Virtanen /* request_key errors don't map nicely to mount(2) 312e2c3d29bSTommi Virtanen errors; don't even try, but still printk */ 313e2c3d29bSTommi Virtanen key_err = PTR_ERR(ukey); 314e2c3d29bSTommi Virtanen switch (key_err) { 315e2c3d29bSTommi Virtanen case -ENOKEY: 316b9a67899SJoe Perches pr_warn("ceph: Mount failed due to key not found: %s\n", 317b9a67899SJoe Perches name); 318e2c3d29bSTommi Virtanen break; 319e2c3d29bSTommi Virtanen case -EKEYEXPIRED: 320b9a67899SJoe Perches pr_warn("ceph: Mount failed due to expired key: %s\n", 321b9a67899SJoe Perches name); 322e2c3d29bSTommi Virtanen break; 323e2c3d29bSTommi Virtanen case -EKEYREVOKED: 324b9a67899SJoe Perches pr_warn("ceph: Mount failed due to revoked key: %s\n", 325b9a67899SJoe Perches name); 326e2c3d29bSTommi Virtanen break; 327e2c3d29bSTommi Virtanen default: 328b9a67899SJoe Perches pr_warn("ceph: Mount failed due to unknown key error %d: %s\n", 329b9a67899SJoe Perches key_err, name); 330e2c3d29bSTommi Virtanen } 331e2c3d29bSTommi Virtanen err = -EPERM; 332e2c3d29bSTommi Virtanen goto out; 333e2c3d29bSTommi Virtanen } 334e2c3d29bSTommi Virtanen 335146aa8b1SDavid Howells ckey = ukey->payload.data[0]; 3364b2a58abSTommi Virtanen err = ceph_crypto_key_clone(dst, ckey); 337e2c3d29bSTommi Virtanen if (err) 338e2c3d29bSTommi Virtanen goto out_key; 339e2c3d29bSTommi Virtanen /* pass through, err is 0 */ 340e2c3d29bSTommi Virtanen 341e2c3d29bSTommi Virtanen out_key: 342e2c3d29bSTommi Virtanen key_put(ukey); 343e2c3d29bSTommi Virtanen out: 344e2c3d29bSTommi Virtanen return err; 345e2c3d29bSTommi Virtanen } 346e2c3d29bSTommi Virtanen 347ee57741cSAlex Elder struct ceph_options * 348ee57741cSAlex Elder ceph_parse_options(char *options, const char *dev_name, 349ee57741cSAlex Elder const char *dev_name_end, 3503d14c5d2SYehuda Sadeh int (*parse_extra_token)(char *c, void *private), 3513d14c5d2SYehuda Sadeh void *private) 3523d14c5d2SYehuda Sadeh { 3533d14c5d2SYehuda Sadeh struct ceph_options *opt; 3543d14c5d2SYehuda Sadeh const char *c; 3553d14c5d2SYehuda Sadeh int err = -ENOMEM; 3563d14c5d2SYehuda Sadeh substring_t argstr[MAX_OPT_ARGS]; 3573d14c5d2SYehuda Sadeh 3583d14c5d2SYehuda Sadeh opt = kzalloc(sizeof(*opt), GFP_KERNEL); 3593d14c5d2SYehuda Sadeh if (!opt) 360ee57741cSAlex Elder return ERR_PTR(-ENOMEM); 3613d14c5d2SYehuda Sadeh opt->mon_addr = kcalloc(CEPH_MAX_MON, sizeof(*opt->mon_addr), 3623d14c5d2SYehuda Sadeh GFP_KERNEL); 3633d14c5d2SYehuda Sadeh if (!opt->mon_addr) 3643d14c5d2SYehuda Sadeh goto out; 3653d14c5d2SYehuda Sadeh 3663d14c5d2SYehuda Sadeh dout("parse_options %p options '%s' dev_name '%s'\n", opt, options, 3673d14c5d2SYehuda Sadeh dev_name); 3683d14c5d2SYehuda Sadeh 3693d14c5d2SYehuda Sadeh /* start with defaults */ 3703d14c5d2SYehuda Sadeh opt->flags = CEPH_OPT_DEFAULT; 3713d14c5d2SYehuda Sadeh opt->osd_keepalive_timeout = CEPH_OSD_KEEPALIVE_DEFAULT; 372a319bf56SIlya Dryomov opt->mount_timeout = CEPH_MOUNT_TIMEOUT_DEFAULT; 373a319bf56SIlya Dryomov opt->osd_idle_ttl = CEPH_OSD_IDLE_TTL_DEFAULT; 3747cc5e38fSIlya Dryomov opt->osd_request_timeout = CEPH_OSD_REQUEST_TIMEOUT_DEFAULT; 3753d14c5d2SYehuda Sadeh 3763d14c5d2SYehuda Sadeh /* get mon ip(s) */ 3773d14c5d2SYehuda Sadeh /* ip1[:port1][,ip2[:port2]...] */ 3783d14c5d2SYehuda Sadeh err = ceph_parse_ips(dev_name, dev_name_end, opt->mon_addr, 3793d14c5d2SYehuda Sadeh CEPH_MAX_MON, &opt->num_mon); 3803d14c5d2SYehuda Sadeh if (err < 0) 3813d14c5d2SYehuda Sadeh goto out; 3823d14c5d2SYehuda Sadeh 3833d14c5d2SYehuda Sadeh /* parse mount options */ 3843d14c5d2SYehuda Sadeh while ((c = strsep(&options, ",")) != NULL) { 38517173c82SChengguang Xu int token, intval; 3863d14c5d2SYehuda Sadeh if (!*c) 3873d14c5d2SYehuda Sadeh continue; 3883d14c5d2SYehuda Sadeh err = -EINVAL; 3893d14c5d2SYehuda Sadeh token = match_token((char *)c, opt_tokens, argstr); 390010e3b48SYehuda Sadeh if (token < 0 && parse_extra_token) { 3913d14c5d2SYehuda Sadeh /* extra? */ 3923d14c5d2SYehuda Sadeh err = parse_extra_token((char *)c, private); 3933d14c5d2SYehuda Sadeh if (err < 0) { 3943d14c5d2SYehuda Sadeh pr_err("bad option at '%s'\n", c); 3953d14c5d2SYehuda Sadeh goto out; 3963d14c5d2SYehuda Sadeh } 3973d14c5d2SYehuda Sadeh continue; 3983d14c5d2SYehuda Sadeh } 3993d14c5d2SYehuda Sadeh if (token < Opt_last_int) { 40017173c82SChengguang Xu err = match_int(&argstr[0], &intval); 40117173c82SChengguang Xu if (err < 0) { 4022f56b6baSIlya Dryomov pr_err("bad option arg (not int) at '%s'\n", c); 40317173c82SChengguang Xu goto out; 4043d14c5d2SYehuda Sadeh } 4053d14c5d2SYehuda Sadeh dout("got int token %d val %d\n", token, intval); 4063d14c5d2SYehuda Sadeh } else if (token > Opt_last_int && token < Opt_last_string) { 4073d14c5d2SYehuda Sadeh dout("got string token %d val %s\n", token, 4083d14c5d2SYehuda Sadeh argstr[0].from); 4093d14c5d2SYehuda Sadeh } else { 4103d14c5d2SYehuda Sadeh dout("got token %d\n", token); 4113d14c5d2SYehuda Sadeh } 4123d14c5d2SYehuda Sadeh switch (token) { 4133d14c5d2SYehuda Sadeh case Opt_ip: 4143d14c5d2SYehuda Sadeh err = ceph_parse_ips(argstr[0].from, 4153d14c5d2SYehuda Sadeh argstr[0].to, 4163d14c5d2SYehuda Sadeh &opt->my_addr, 4173d14c5d2SYehuda Sadeh 1, NULL); 4183d14c5d2SYehuda Sadeh if (err < 0) 4193d14c5d2SYehuda Sadeh goto out; 4203d14c5d2SYehuda Sadeh opt->flags |= CEPH_OPT_MYIP; 4213d14c5d2SYehuda Sadeh break; 4223d14c5d2SYehuda Sadeh 4233d14c5d2SYehuda Sadeh case Opt_fsid: 4243d14c5d2SYehuda Sadeh err = parse_fsid(argstr[0].from, &opt->fsid); 4253d14c5d2SYehuda Sadeh if (err == 0) 4263d14c5d2SYehuda Sadeh opt->flags |= CEPH_OPT_FSID; 4273d14c5d2SYehuda Sadeh break; 4283d14c5d2SYehuda Sadeh case Opt_name: 429937441f3SChengguang Xu kfree(opt->name); 4303d14c5d2SYehuda Sadeh opt->name = kstrndup(argstr[0].from, 4313d14c5d2SYehuda Sadeh argstr[0].to-argstr[0].from, 4323d14c5d2SYehuda Sadeh GFP_KERNEL); 433affff077SChengguang Xu if (!opt->name) { 434affff077SChengguang Xu err = -ENOMEM; 435affff077SChengguang Xu goto out; 436affff077SChengguang Xu } 4373d14c5d2SYehuda Sadeh break; 4383d14c5d2SYehuda Sadeh case Opt_secret: 439937441f3SChengguang Xu ceph_crypto_key_destroy(opt->key); 440937441f3SChengguang Xu kfree(opt->key); 441937441f3SChengguang Xu 4428323c3aaSTommi Virtanen opt->key = kzalloc(sizeof(*opt->key), GFP_KERNEL); 4438323c3aaSTommi Virtanen if (!opt->key) { 4448323c3aaSTommi Virtanen err = -ENOMEM; 4458323c3aaSTommi Virtanen goto out; 4468323c3aaSTommi Virtanen } 4478323c3aaSTommi Virtanen err = ceph_crypto_key_unarmor(opt->key, argstr[0].from); 4488323c3aaSTommi Virtanen if (err < 0) 4498323c3aaSTommi Virtanen goto out; 4503d14c5d2SYehuda Sadeh break; 451e2c3d29bSTommi Virtanen case Opt_key: 452937441f3SChengguang Xu ceph_crypto_key_destroy(opt->key); 453937441f3SChengguang Xu kfree(opt->key); 454937441f3SChengguang Xu 455e2c3d29bSTommi Virtanen opt->key = kzalloc(sizeof(*opt->key), GFP_KERNEL); 456e2c3d29bSTommi Virtanen if (!opt->key) { 457e2c3d29bSTommi Virtanen err = -ENOMEM; 458e2c3d29bSTommi Virtanen goto out; 459e2c3d29bSTommi Virtanen } 460e2c3d29bSTommi Virtanen err = get_secret(opt->key, argstr[0].from); 461e2c3d29bSTommi Virtanen if (err < 0) 462e2c3d29bSTommi Virtanen goto out; 463e2c3d29bSTommi Virtanen break; 4643d14c5d2SYehuda Sadeh 4653d14c5d2SYehuda Sadeh /* misc */ 4663d14c5d2SYehuda Sadeh case Opt_osdtimeout: 467b9a67899SJoe Perches pr_warn("ignoring deprecated osdtimeout option\n"); 4683d14c5d2SYehuda Sadeh break; 4693d14c5d2SYehuda Sadeh case Opt_osdkeepalivetimeout: 470a319bf56SIlya Dryomov /* 0 isn't well defined right now, reject it */ 471a319bf56SIlya Dryomov if (intval < 1 || intval > INT_MAX / 1000) { 472a319bf56SIlya Dryomov pr_err("osdkeepalive out of range\n"); 473a319bf56SIlya Dryomov err = -EINVAL; 474a319bf56SIlya Dryomov goto out; 475a319bf56SIlya Dryomov } 476a319bf56SIlya Dryomov opt->osd_keepalive_timeout = 477a319bf56SIlya Dryomov msecs_to_jiffies(intval * 1000); 4783d14c5d2SYehuda Sadeh break; 4793d14c5d2SYehuda Sadeh case Opt_osd_idle_ttl: 480a319bf56SIlya Dryomov /* 0 isn't well defined right now, reject it */ 481a319bf56SIlya Dryomov if (intval < 1 || intval > INT_MAX / 1000) { 482a319bf56SIlya Dryomov pr_err("osd_idle_ttl out of range\n"); 483a319bf56SIlya Dryomov err = -EINVAL; 484a319bf56SIlya Dryomov goto out; 485a319bf56SIlya Dryomov } 486a319bf56SIlya Dryomov opt->osd_idle_ttl = msecs_to_jiffies(intval * 1000); 4873d14c5d2SYehuda Sadeh break; 4883d14c5d2SYehuda Sadeh case Opt_mount_timeout: 489a319bf56SIlya Dryomov /* 0 is "wait forever" (i.e. infinite timeout) */ 490a319bf56SIlya Dryomov if (intval < 0 || intval > INT_MAX / 1000) { 491a319bf56SIlya Dryomov pr_err("mount_timeout out of range\n"); 492a319bf56SIlya Dryomov err = -EINVAL; 493a319bf56SIlya Dryomov goto out; 494a319bf56SIlya Dryomov } 495a319bf56SIlya Dryomov opt->mount_timeout = msecs_to_jiffies(intval * 1000); 4963d14c5d2SYehuda Sadeh break; 4977cc5e38fSIlya Dryomov case Opt_osd_request_timeout: 4987cc5e38fSIlya Dryomov /* 0 is "wait forever" (i.e. infinite timeout) */ 4997cc5e38fSIlya Dryomov if (intval < 0 || intval > INT_MAX / 1000) { 5007cc5e38fSIlya Dryomov pr_err("osd_request_timeout out of range\n"); 5017cc5e38fSIlya Dryomov err = -EINVAL; 5027cc5e38fSIlya Dryomov goto out; 5037cc5e38fSIlya Dryomov } 5047cc5e38fSIlya Dryomov opt->osd_request_timeout = msecs_to_jiffies(intval * 1000); 5057cc5e38fSIlya Dryomov break; 5063d14c5d2SYehuda Sadeh 507cffaba15SAlex Elder case Opt_share: 508cffaba15SAlex Elder opt->flags &= ~CEPH_OPT_NOSHARE; 509cffaba15SAlex Elder break; 5103d14c5d2SYehuda Sadeh case Opt_noshare: 5113d14c5d2SYehuda Sadeh opt->flags |= CEPH_OPT_NOSHARE; 5123d14c5d2SYehuda Sadeh break; 5133d14c5d2SYehuda Sadeh 514cffaba15SAlex Elder case Opt_crc: 515cffaba15SAlex Elder opt->flags &= ~CEPH_OPT_NOCRC; 516cffaba15SAlex Elder break; 5173d14c5d2SYehuda Sadeh case Opt_nocrc: 5183d14c5d2SYehuda Sadeh opt->flags |= CEPH_OPT_NOCRC; 5193d14c5d2SYehuda Sadeh break; 520ba988f87SChaitanya Huilgol 521a3fc9800SYan, Zheng case Opt_cephx_require_signatures: 522a3fc9800SYan, Zheng opt->flags &= ~CEPH_OPT_NOMSGAUTH; 523a3fc9800SYan, Zheng break; 524a3fc9800SYan, Zheng case Opt_nocephx_require_signatures: 525a3fc9800SYan, Zheng opt->flags |= CEPH_OPT_NOMSGAUTH; 526a3fc9800SYan, Zheng break; 527a51983e4SIlya Dryomov case Opt_cephx_sign_messages: 528a51983e4SIlya Dryomov opt->flags &= ~CEPH_OPT_NOMSGSIGN; 529a51983e4SIlya Dryomov break; 530a51983e4SIlya Dryomov case Opt_nocephx_sign_messages: 531a51983e4SIlya Dryomov opt->flags |= CEPH_OPT_NOMSGSIGN; 532a51983e4SIlya Dryomov break; 5333d14c5d2SYehuda Sadeh 534ba988f87SChaitanya Huilgol case Opt_tcp_nodelay: 535ba988f87SChaitanya Huilgol opt->flags |= CEPH_OPT_TCP_NODELAY; 536ba988f87SChaitanya Huilgol break; 537ba988f87SChaitanya Huilgol case Opt_notcp_nodelay: 538ba988f87SChaitanya Huilgol opt->flags &= ~CEPH_OPT_TCP_NODELAY; 539ba988f87SChaitanya Huilgol break; 540ba988f87SChaitanya Huilgol 54102b2f549SDongsheng Yang case Opt_abort_on_full: 54202b2f549SDongsheng Yang opt->flags |= CEPH_OPT_ABORT_ON_FULL; 54302b2f549SDongsheng Yang break; 54402b2f549SDongsheng Yang 5453d14c5d2SYehuda Sadeh default: 5463d14c5d2SYehuda Sadeh BUG_ON(token); 5473d14c5d2SYehuda Sadeh } 5483d14c5d2SYehuda Sadeh } 5493d14c5d2SYehuda Sadeh 5503d14c5d2SYehuda Sadeh /* success */ 551ee57741cSAlex Elder return opt; 5523d14c5d2SYehuda Sadeh 5533d14c5d2SYehuda Sadeh out: 5543d14c5d2SYehuda Sadeh ceph_destroy_options(opt); 555ee57741cSAlex Elder return ERR_PTR(err); 5563d14c5d2SYehuda Sadeh } 5573d14c5d2SYehuda Sadeh EXPORT_SYMBOL(ceph_parse_options); 5583d14c5d2SYehuda Sadeh 55902b2f549SDongsheng Yang int ceph_print_client_options(struct seq_file *m, struct ceph_client *client, 56002b2f549SDongsheng Yang bool show_all) 561ff40f9aeSIlya Dryomov { 562ff40f9aeSIlya Dryomov struct ceph_options *opt = client->options; 563ff40f9aeSIlya Dryomov size_t pos = m->count; 564ff40f9aeSIlya Dryomov 565a068acf2SKees Cook if (opt->name) { 566a068acf2SKees Cook seq_puts(m, "name="); 567a068acf2SKees Cook seq_escape(m, opt->name, ", \t\n\\"); 568a068acf2SKees Cook seq_putc(m, ','); 569a068acf2SKees Cook } 570ff40f9aeSIlya Dryomov if (opt->key) 571ff40f9aeSIlya Dryomov seq_puts(m, "secret=<hidden>,"); 572ff40f9aeSIlya Dryomov 573ff40f9aeSIlya Dryomov if (opt->flags & CEPH_OPT_FSID) 574ff40f9aeSIlya Dryomov seq_printf(m, "fsid=%pU,", &opt->fsid); 575ff40f9aeSIlya Dryomov if (opt->flags & CEPH_OPT_NOSHARE) 576ff40f9aeSIlya Dryomov seq_puts(m, "noshare,"); 577ff40f9aeSIlya Dryomov if (opt->flags & CEPH_OPT_NOCRC) 578ff40f9aeSIlya Dryomov seq_puts(m, "nocrc,"); 579ff40f9aeSIlya Dryomov if (opt->flags & CEPH_OPT_NOMSGAUTH) 580ff40f9aeSIlya Dryomov seq_puts(m, "nocephx_require_signatures,"); 581a51983e4SIlya Dryomov if (opt->flags & CEPH_OPT_NOMSGSIGN) 582a51983e4SIlya Dryomov seq_puts(m, "nocephx_sign_messages,"); 583ff40f9aeSIlya Dryomov if ((opt->flags & CEPH_OPT_TCP_NODELAY) == 0) 584ff40f9aeSIlya Dryomov seq_puts(m, "notcp_nodelay,"); 58502b2f549SDongsheng Yang if (show_all && (opt->flags & CEPH_OPT_ABORT_ON_FULL)) 58602b2f549SDongsheng Yang seq_puts(m, "abort_on_full,"); 587ff40f9aeSIlya Dryomov 588ff40f9aeSIlya Dryomov if (opt->mount_timeout != CEPH_MOUNT_TIMEOUT_DEFAULT) 589a319bf56SIlya Dryomov seq_printf(m, "mount_timeout=%d,", 590a319bf56SIlya Dryomov jiffies_to_msecs(opt->mount_timeout) / 1000); 591ff40f9aeSIlya Dryomov if (opt->osd_idle_ttl != CEPH_OSD_IDLE_TTL_DEFAULT) 592a319bf56SIlya Dryomov seq_printf(m, "osd_idle_ttl=%d,", 593a319bf56SIlya Dryomov jiffies_to_msecs(opt->osd_idle_ttl) / 1000); 594ff40f9aeSIlya Dryomov if (opt->osd_keepalive_timeout != CEPH_OSD_KEEPALIVE_DEFAULT) 595ff40f9aeSIlya Dryomov seq_printf(m, "osdkeepalivetimeout=%d,", 596a319bf56SIlya Dryomov jiffies_to_msecs(opt->osd_keepalive_timeout) / 1000); 5977cc5e38fSIlya Dryomov if (opt->osd_request_timeout != CEPH_OSD_REQUEST_TIMEOUT_DEFAULT) 5987cc5e38fSIlya Dryomov seq_printf(m, "osd_request_timeout=%d,", 5997cc5e38fSIlya Dryomov jiffies_to_msecs(opt->osd_request_timeout) / 1000); 600ff40f9aeSIlya Dryomov 601ff40f9aeSIlya Dryomov /* drop redundant comma */ 602ff40f9aeSIlya Dryomov if (m->count != pos) 603ff40f9aeSIlya Dryomov m->count--; 604ff40f9aeSIlya Dryomov 605ff40f9aeSIlya Dryomov return 0; 606ff40f9aeSIlya Dryomov } 607ff40f9aeSIlya Dryomov EXPORT_SYMBOL(ceph_print_client_options); 608ff40f9aeSIlya Dryomov 609005a07bfSIlya Dryomov struct ceph_entity_addr *ceph_client_addr(struct ceph_client *client) 610005a07bfSIlya Dryomov { 611005a07bfSIlya Dryomov return &client->msgr.inst.addr; 612005a07bfSIlya Dryomov } 613005a07bfSIlya Dryomov EXPORT_SYMBOL(ceph_client_addr); 614005a07bfSIlya Dryomov 615033268a5SIlya Dryomov u64 ceph_client_gid(struct ceph_client *client) 6163d14c5d2SYehuda Sadeh { 6173d14c5d2SYehuda Sadeh return client->monc.auth->global_id; 6183d14c5d2SYehuda Sadeh } 619033268a5SIlya Dryomov EXPORT_SYMBOL(ceph_client_gid); 6203d14c5d2SYehuda Sadeh 6213d14c5d2SYehuda Sadeh /* 6223d14c5d2SYehuda Sadeh * create a fresh client instance 6233d14c5d2SYehuda Sadeh */ 62474da4a0fSIlya Dryomov struct ceph_client *ceph_create_client(struct ceph_options *opt, void *private) 6253d14c5d2SYehuda Sadeh { 6263d14c5d2SYehuda Sadeh struct ceph_client *client; 6276ab00d46SSage Weil struct ceph_entity_addr *myaddr = NULL; 628ae5b806aSJason A. Donenfeld int err; 629ae5b806aSJason A. Donenfeld 630ae5b806aSJason A. Donenfeld err = wait_for_random_bytes(); 631ae5b806aSJason A. Donenfeld if (err < 0) 632ae5b806aSJason A. Donenfeld return ERR_PTR(err); 6333d14c5d2SYehuda Sadeh 6343d14c5d2SYehuda Sadeh client = kzalloc(sizeof(*client), GFP_KERNEL); 6353d14c5d2SYehuda Sadeh if (client == NULL) 6363d14c5d2SYehuda Sadeh return ERR_PTR(-ENOMEM); 6373d14c5d2SYehuda Sadeh 6383d14c5d2SYehuda Sadeh client->private = private; 6393d14c5d2SYehuda Sadeh client->options = opt; 6403d14c5d2SYehuda Sadeh 6413d14c5d2SYehuda Sadeh mutex_init(&client->mount_mutex); 6423d14c5d2SYehuda Sadeh init_waitqueue_head(&client->auth_wq); 6433d14c5d2SYehuda Sadeh client->auth_err = 0; 6443d14c5d2SYehuda Sadeh 6453d14c5d2SYehuda Sadeh client->extra_mon_dispatch = NULL; 64674da4a0fSIlya Dryomov client->supported_features = CEPH_FEATURES_SUPPORTED_DEFAULT; 64774da4a0fSIlya Dryomov client->required_features = CEPH_FEATURES_REQUIRED_DEFAULT; 64874da4a0fSIlya Dryomov 64974da4a0fSIlya Dryomov if (!ceph_test_opt(client, NOMSGAUTH)) 65074da4a0fSIlya Dryomov client->required_features |= CEPH_FEATURE_MSG_AUTH; 6513d14c5d2SYehuda Sadeh 6526ab00d46SSage Weil /* msgr */ 6536ab00d46SSage Weil if (ceph_test_opt(client, MYIP)) 6546ab00d46SSage Weil myaddr = &client->options->my_addr; 655ba988f87SChaitanya Huilgol 656859bff51SIlya Dryomov ceph_messenger_init(&client->msgr, myaddr); 6573d14c5d2SYehuda Sadeh 6583d14c5d2SYehuda Sadeh /* subsystems */ 6593d14c5d2SYehuda Sadeh err = ceph_monc_init(&client->monc, client); 6603d14c5d2SYehuda Sadeh if (err < 0) 66115d9882cSAlex Elder goto fail; 6623d14c5d2SYehuda Sadeh err = ceph_osdc_init(&client->osdc, client); 6633d14c5d2SYehuda Sadeh if (err < 0) 6643d14c5d2SYehuda Sadeh goto fail_monc; 6653d14c5d2SYehuda Sadeh 6663d14c5d2SYehuda Sadeh return client; 6673d14c5d2SYehuda Sadeh 6683d14c5d2SYehuda Sadeh fail_monc: 6693d14c5d2SYehuda Sadeh ceph_monc_stop(&client->monc); 6703d14c5d2SYehuda Sadeh fail: 671757856d2SIlya Dryomov ceph_messenger_fini(&client->msgr); 6723d14c5d2SYehuda Sadeh kfree(client); 6733d14c5d2SYehuda Sadeh return ERR_PTR(err); 6743d14c5d2SYehuda Sadeh } 6753d14c5d2SYehuda Sadeh EXPORT_SYMBOL(ceph_create_client); 6763d14c5d2SYehuda Sadeh 6773d14c5d2SYehuda Sadeh void ceph_destroy_client(struct ceph_client *client) 6783d14c5d2SYehuda Sadeh { 6793d14c5d2SYehuda Sadeh dout("destroy_client %p\n", client); 6803d14c5d2SYehuda Sadeh 681a2a32584SGuanjun He atomic_set(&client->msgr.stopping, 1); 682a2a32584SGuanjun He 6833d14c5d2SYehuda Sadeh /* unmount */ 6843d14c5d2SYehuda Sadeh ceph_osdc_stop(&client->osdc); 6853d14c5d2SYehuda Sadeh ceph_monc_stop(&client->monc); 686757856d2SIlya Dryomov ceph_messenger_fini(&client->msgr); 6873d14c5d2SYehuda Sadeh 6883d14c5d2SYehuda Sadeh ceph_debugfs_client_cleanup(client); 6893d14c5d2SYehuda Sadeh 6903d14c5d2SYehuda Sadeh ceph_destroy_options(client->options); 6913d14c5d2SYehuda Sadeh 6923d14c5d2SYehuda Sadeh kfree(client); 6933d14c5d2SYehuda Sadeh dout("destroy_client %p done\n", client); 6943d14c5d2SYehuda Sadeh } 6953d14c5d2SYehuda Sadeh EXPORT_SYMBOL(ceph_destroy_client); 6963d14c5d2SYehuda Sadeh 697*120a75eaSYan, Zheng void ceph_reset_client_addr(struct ceph_client *client) 698*120a75eaSYan, Zheng { 699*120a75eaSYan, Zheng ceph_messenger_reset_nonce(&client->msgr); 700*120a75eaSYan, Zheng ceph_monc_reopen_session(&client->monc); 701*120a75eaSYan, Zheng ceph_osdc_reopen_osds(&client->osdc); 702*120a75eaSYan, Zheng } 703*120a75eaSYan, Zheng EXPORT_SYMBOL(ceph_reset_client_addr); 704*120a75eaSYan, Zheng 7053d14c5d2SYehuda Sadeh /* 7063d14c5d2SYehuda Sadeh * true if we have the mon map (and have thus joined the cluster) 7073d14c5d2SYehuda Sadeh */ 7083b33f692SZhang Zhuoyu static bool have_mon_and_osd_map(struct ceph_client *client) 7093d14c5d2SYehuda Sadeh { 7103d14c5d2SYehuda Sadeh return client->monc.monmap && client->monc.monmap->epoch && 7113d14c5d2SYehuda Sadeh client->osdc.osdmap && client->osdc.osdmap->epoch; 7123d14c5d2SYehuda Sadeh } 7133d14c5d2SYehuda Sadeh 7143d14c5d2SYehuda Sadeh /* 7153d14c5d2SYehuda Sadeh * mount: join the ceph cluster, and open root directory. 7163d14c5d2SYehuda Sadeh */ 7173d14c5d2SYehuda Sadeh int __ceph_open_session(struct ceph_client *client, unsigned long started) 7183d14c5d2SYehuda Sadeh { 719a319bf56SIlya Dryomov unsigned long timeout = client->options->mount_timeout; 720216639ddSIlya Dryomov long err; 7213d14c5d2SYehuda Sadeh 7223d14c5d2SYehuda Sadeh /* open session, and wait for mon and osd maps */ 7233d14c5d2SYehuda Sadeh err = ceph_monc_open_session(&client->monc); 7243d14c5d2SYehuda Sadeh if (err < 0) 7253d14c5d2SYehuda Sadeh return err; 7263d14c5d2SYehuda Sadeh 7273d14c5d2SYehuda Sadeh while (!have_mon_and_osd_map(client)) { 7283d14c5d2SYehuda Sadeh if (timeout && time_after_eq(jiffies, started + timeout)) 729216639ddSIlya Dryomov return -ETIMEDOUT; 7303d14c5d2SYehuda Sadeh 7313d14c5d2SYehuda Sadeh /* wait */ 7323d14c5d2SYehuda Sadeh dout("mount waiting for mon_map\n"); 7333d14c5d2SYehuda Sadeh err = wait_event_interruptible_timeout(client->auth_wq, 7343d14c5d2SYehuda Sadeh have_mon_and_osd_map(client) || (client->auth_err < 0), 735a319bf56SIlya Dryomov ceph_timeout_jiffies(timeout)); 736216639ddSIlya Dryomov if (err < 0) 7373d14c5d2SYehuda Sadeh return err; 7383d14c5d2SYehuda Sadeh if (client->auth_err < 0) 7393d14c5d2SYehuda Sadeh return client->auth_err; 7403d14c5d2SYehuda Sadeh } 7413d14c5d2SYehuda Sadeh 742033268a5SIlya Dryomov pr_info("client%llu fsid %pU\n", ceph_client_gid(client), 743033268a5SIlya Dryomov &client->fsid); 74402ac956cSIlya Dryomov ceph_debugfs_client_init(client); 74502ac956cSIlya Dryomov 7463d14c5d2SYehuda Sadeh return 0; 7473d14c5d2SYehuda Sadeh } 7483d14c5d2SYehuda Sadeh EXPORT_SYMBOL(__ceph_open_session); 7493d14c5d2SYehuda Sadeh 7503d14c5d2SYehuda Sadeh int ceph_open_session(struct ceph_client *client) 7513d14c5d2SYehuda Sadeh { 7523d14c5d2SYehuda Sadeh int ret; 7533d14c5d2SYehuda Sadeh unsigned long started = jiffies; /* note the start time */ 7543d14c5d2SYehuda Sadeh 7553d14c5d2SYehuda Sadeh dout("open_session start\n"); 7563d14c5d2SYehuda Sadeh mutex_lock(&client->mount_mutex); 7573d14c5d2SYehuda Sadeh 7583d14c5d2SYehuda Sadeh ret = __ceph_open_session(client, started); 7593d14c5d2SYehuda Sadeh 7603d14c5d2SYehuda Sadeh mutex_unlock(&client->mount_mutex); 7613d14c5d2SYehuda Sadeh return ret; 7623d14c5d2SYehuda Sadeh } 7633d14c5d2SYehuda Sadeh EXPORT_SYMBOL(ceph_open_session); 7643d14c5d2SYehuda Sadeh 765bb229bbbSIlya Dryomov int ceph_wait_for_latest_osdmap(struct ceph_client *client, 766bb229bbbSIlya Dryomov unsigned long timeout) 767bb229bbbSIlya Dryomov { 768bb229bbbSIlya Dryomov u64 newest_epoch; 769bb229bbbSIlya Dryomov int ret; 770bb229bbbSIlya Dryomov 771bb229bbbSIlya Dryomov ret = ceph_monc_get_version(&client->monc, "osdmap", &newest_epoch); 772bb229bbbSIlya Dryomov if (ret) 773bb229bbbSIlya Dryomov return ret; 774bb229bbbSIlya Dryomov 775bb229bbbSIlya Dryomov if (client->osdc.osdmap->epoch >= newest_epoch) 776bb229bbbSIlya Dryomov return 0; 777bb229bbbSIlya Dryomov 778bb229bbbSIlya Dryomov ceph_osdc_maybe_request_map(&client->osdc); 779bb229bbbSIlya Dryomov return ceph_monc_wait_osdmap(&client->monc, newest_epoch, timeout); 780bb229bbbSIlya Dryomov } 781bb229bbbSIlya Dryomov EXPORT_SYMBOL(ceph_wait_for_latest_osdmap); 7823d14c5d2SYehuda Sadeh 7833d14c5d2SYehuda Sadeh static int __init init_ceph_lib(void) 7843d14c5d2SYehuda Sadeh { 7853d14c5d2SYehuda Sadeh int ret = 0; 7863d14c5d2SYehuda Sadeh 7871a829ff2SGreg Kroah-Hartman ceph_debugfs_init(); 7883d14c5d2SYehuda Sadeh 7894b2a58abSTommi Virtanen ret = ceph_crypto_init(); 7903d14c5d2SYehuda Sadeh if (ret < 0) 7913d14c5d2SYehuda Sadeh goto out_debugfs; 7923d14c5d2SYehuda Sadeh 7934b2a58abSTommi Virtanen ret = ceph_msgr_init(); 7944b2a58abSTommi Virtanen if (ret < 0) 7954b2a58abSTommi Virtanen goto out_crypto; 7964b2a58abSTommi Virtanen 7975522ae0bSAlex Elder ret = ceph_osdc_setup(); 7985522ae0bSAlex Elder if (ret < 0) 7995522ae0bSAlex Elder goto out_msgr; 8005522ae0bSAlex Elder 8014f6a7e5eSSage Weil pr_info("loaded (mon/osd proto %d/%d)\n", 8024f6a7e5eSSage Weil CEPH_MONC_PROTOCOL, CEPH_OSDC_PROTOCOL); 8033d14c5d2SYehuda Sadeh 8043d14c5d2SYehuda Sadeh return 0; 8053d14c5d2SYehuda Sadeh 8065522ae0bSAlex Elder out_msgr: 8075522ae0bSAlex Elder ceph_msgr_exit(); 8084b2a58abSTommi Virtanen out_crypto: 8094b2a58abSTommi Virtanen ceph_crypto_shutdown(); 8103d14c5d2SYehuda Sadeh out_debugfs: 8113d14c5d2SYehuda Sadeh ceph_debugfs_cleanup(); 8123d14c5d2SYehuda Sadeh return ret; 8133d14c5d2SYehuda Sadeh } 8143d14c5d2SYehuda Sadeh 8153d14c5d2SYehuda Sadeh static void __exit exit_ceph_lib(void) 8163d14c5d2SYehuda Sadeh { 8173d14c5d2SYehuda Sadeh dout("exit_ceph_lib\n"); 81851e92737SYan, Zheng WARN_ON(!ceph_strings_empty()); 81951e92737SYan, Zheng 8205522ae0bSAlex Elder ceph_osdc_cleanup(); 8213d14c5d2SYehuda Sadeh ceph_msgr_exit(); 8224b2a58abSTommi Virtanen ceph_crypto_shutdown(); 8233d14c5d2SYehuda Sadeh ceph_debugfs_cleanup(); 8243d14c5d2SYehuda Sadeh } 8253d14c5d2SYehuda Sadeh 8263d14c5d2SYehuda Sadeh module_init(init_ceph_lib); 8273d14c5d2SYehuda Sadeh module_exit(exit_ceph_lib); 8283d14c5d2SYehuda Sadeh 8293d14c5d2SYehuda Sadeh MODULE_AUTHOR("Sage Weil <sage@newdream.net>"); 8303d14c5d2SYehuda Sadeh MODULE_AUTHOR("Yehuda Sadeh <yehuda@hq.newdream.net>"); 8313d14c5d2SYehuda Sadeh MODULE_AUTHOR("Patience Warnick <patience@newdream.net>"); 8326c13a6bbSHong Zhiguo MODULE_DESCRIPTION("Ceph core library"); 8333d14c5d2SYehuda Sadeh MODULE_LICENSE("GPL"); 834