2019-05-19 20:08:20 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2010-04-07 06:14:15 +08:00
|
|
|
|
|
|
|
#include <linux/ceph/ceph_debug.h>
|
|
|
|
#include <linux/backing-dev.h>
|
|
|
|
#include <linux/ctype.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/inet.h>
|
|
|
|
#include <linux/in6.h>
|
2011-03-26 07:40:48 +08:00
|
|
|
#include <linux/key.h>
|
2011-03-29 05:59:38 +08:00
|
|
|
#include <keys/ceph-type.h>
|
2010-04-07 06:14:15 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/mount.h>
|
2015-06-25 22:47:45 +08:00
|
|
|
#include <linux/nsproxy.h>
|
2019-03-26 00:38:32 +08:00
|
|
|
#include <linux/fs_parser.h>
|
2010-04-07 06:14:15 +08:00
|
|
|
#include <linux/sched.h>
|
2019-08-31 02:44:24 +08:00
|
|
|
#include <linux/sched/mm.h>
|
2010-04-07 06:14:15 +08:00
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/statfs.h>
|
|
|
|
#include <linux/string.h>
|
2014-01-10 02:08:21 +08:00
|
|
|
#include <linux/vmalloc.h>
|
2010-04-07 06:14:15 +08:00
|
|
|
|
|
|
|
|
2012-07-31 07:23:22 +08:00
|
|
|
#include <linux/ceph/ceph_features.h>
|
2010-04-07 06:14:15 +08:00
|
|
|
#include <linux/ceph/libceph.h>
|
|
|
|
#include <linux/ceph/debugfs.h>
|
|
|
|
#include <linux/ceph/decode.h>
|
|
|
|
#include <linux/ceph/mon_client.h>
|
|
|
|
#include <linux/ceph/auth.h>
|
2011-03-26 07:32:57 +08:00
|
|
|
#include "crypto.h"
|
2010-04-07 06:14:15 +08:00
|
|
|
|
|
|
|
|
2013-01-31 01:13:33 +08:00
|
|
|
/*
|
|
|
|
* Module compatibility interface. For now it doesn't do anything,
|
|
|
|
* but its existence signals a certain level of functionality.
|
|
|
|
*
|
|
|
|
* The data buffer is used to pass information both to and from
|
|
|
|
* libceph. The return value indicates whether libceph determines
|
|
|
|
* it is compatible with the caller (from another kernel module),
|
|
|
|
* given the provided data.
|
|
|
|
*
|
|
|
|
* The data pointer can be null.
|
|
|
|
*/
|
|
|
|
bool libceph_compatible(void *data)
|
|
|
|
{
|
2013-01-31 01:13:33 +08:00
|
|
|
return true;
|
2013-01-31 01:13:33 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(libceph_compatible);
|
2010-04-07 06:14:15 +08:00
|
|
|
|
2017-03-04 01:16:07 +08:00
|
|
|
static int param_get_supported_features(char *buffer,
|
|
|
|
const struct kernel_param *kp)
|
|
|
|
{
|
|
|
|
return sprintf(buffer, "0x%llx", CEPH_FEATURES_SUPPORTED_DEFAULT);
|
|
|
|
}
|
|
|
|
static const struct kernel_param_ops param_ops_supported_features = {
|
|
|
|
.get = param_get_supported_features,
|
|
|
|
};
|
|
|
|
module_param_cb(supported_features, ¶m_ops_supported_features, NULL,
|
2018-03-24 06:54:38 +08:00
|
|
|
0444);
|
2017-03-04 01:16:07 +08:00
|
|
|
|
2010-04-07 06:14:15 +08:00
|
|
|
const char *ceph_msg_type_name(int type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case CEPH_MSG_SHUTDOWN: return "shutdown";
|
|
|
|
case CEPH_MSG_PING: return "ping";
|
|
|
|
case CEPH_MSG_AUTH: return "auth";
|
|
|
|
case CEPH_MSG_AUTH_REPLY: return "auth_reply";
|
|
|
|
case CEPH_MSG_MON_MAP: return "mon_map";
|
|
|
|
case CEPH_MSG_MON_GET_MAP: return "mon_get_map";
|
|
|
|
case CEPH_MSG_MON_SUBSCRIBE: return "mon_subscribe";
|
|
|
|
case CEPH_MSG_MON_SUBSCRIBE_ACK: return "mon_subscribe_ack";
|
|
|
|
case CEPH_MSG_STATFS: return "statfs";
|
|
|
|
case CEPH_MSG_STATFS_REPLY: return "statfs_reply";
|
2014-05-13 15:19:26 +08:00
|
|
|
case CEPH_MSG_MON_GET_VERSION: return "mon_get_version";
|
|
|
|
case CEPH_MSG_MON_GET_VERSION_REPLY: return "mon_get_version_reply";
|
2010-04-07 06:14:15 +08:00
|
|
|
case CEPH_MSG_MDS_MAP: return "mds_map";
|
2018-02-22 15:47:05 +08:00
|
|
|
case CEPH_MSG_FS_MAP_USER: return "fs_map_user";
|
2010-04-07 06:14:15 +08:00
|
|
|
case CEPH_MSG_CLIENT_SESSION: return "client_session";
|
|
|
|
case CEPH_MSG_CLIENT_RECONNECT: return "client_reconnect";
|
|
|
|
case CEPH_MSG_CLIENT_REQUEST: return "client_request";
|
|
|
|
case CEPH_MSG_CLIENT_REQUEST_FORWARD: return "client_request_forward";
|
|
|
|
case CEPH_MSG_CLIENT_REPLY: return "client_reply";
|
|
|
|
case CEPH_MSG_CLIENT_CAPS: return "client_caps";
|
|
|
|
case CEPH_MSG_CLIENT_CAPRELEASE: return "client_cap_release";
|
2018-01-05 18:47:18 +08:00
|
|
|
case CEPH_MSG_CLIENT_QUOTA: return "client_quota";
|
2010-04-07 06:14:15 +08:00
|
|
|
case CEPH_MSG_CLIENT_SNAP: return "client_snap";
|
|
|
|
case CEPH_MSG_CLIENT_LEASE: return "client_lease";
|
2018-02-22 15:47:05 +08:00
|
|
|
case CEPH_MSG_POOLOP_REPLY: return "poolop_reply";
|
|
|
|
case CEPH_MSG_POOLOP: return "poolop";
|
|
|
|
case CEPH_MSG_MON_COMMAND: return "mon_command";
|
|
|
|
case CEPH_MSG_MON_COMMAND_ACK: return "mon_command_ack";
|
2010-04-07 06:14:15 +08:00
|
|
|
case CEPH_MSG_OSD_MAP: return "osd_map";
|
|
|
|
case CEPH_MSG_OSD_OP: return "osd_op";
|
|
|
|
case CEPH_MSG_OSD_OPREPLY: return "osd_opreply";
|
2011-03-22 06:07:16 +08:00
|
|
|
case CEPH_MSG_WATCH_NOTIFY: return "watch_notify";
|
2017-06-19 18:18:05 +08:00
|
|
|
case CEPH_MSG_OSD_BACKOFF: return "osd_backoff";
|
2010-04-07 06:14:15 +08:00
|
|
|
default: return "unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ceph_msg_type_name);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initially learn our fsid, or verify an fsid matches.
|
|
|
|
*/
|
|
|
|
int ceph_check_fsid(struct ceph_client *client, struct ceph_fsid *fsid)
|
|
|
|
{
|
|
|
|
if (client->have_fsid) {
|
|
|
|
if (ceph_fsid_compare(&client->fsid, fsid)) {
|
|
|
|
pr_err("bad fsid, had %pU got %pU",
|
|
|
|
&client->fsid, fsid);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
memcpy(&client->fsid, fsid, sizeof(*fsid));
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ceph_check_fsid);
|
|
|
|
|
|
|
|
static int strcmp_null(const char *s1, const char *s2)
|
|
|
|
{
|
|
|
|
if (!s1 && !s2)
|
|
|
|
return 0;
|
|
|
|
if (s1 && !s2)
|
|
|
|
return -1;
|
|
|
|
if (!s1 && s2)
|
|
|
|
return 1;
|
|
|
|
return strcmp(s1, s2);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ceph_compare_options(struct ceph_options *new_opt,
|
|
|
|
struct ceph_client *client)
|
|
|
|
{
|
|
|
|
struct ceph_options *opt1 = new_opt;
|
|
|
|
struct ceph_options *opt2 = client->options;
|
|
|
|
int ofs = offsetof(struct ceph_options, mon_addr);
|
|
|
|
int i;
|
|
|
|
int ret;
|
|
|
|
|
2015-06-25 22:47:45 +08:00
|
|
|
/*
|
|
|
|
* Don't bother comparing options if network namespaces don't
|
|
|
|
* match.
|
|
|
|
*/
|
|
|
|
if (!net_eq(current->nsproxy->net_ns, read_pnet(&client->msgr.net)))
|
|
|
|
return -1;
|
|
|
|
|
2010-04-07 06:14:15 +08:00
|
|
|
ret = memcmp(opt1, opt2, ofs);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = strcmp_null(opt1->name, opt2->name);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2011-03-26 07:32:57 +08:00
|
|
|
if (opt1->key && !opt2->key)
|
|
|
|
return -1;
|
|
|
|
if (!opt1->key && opt2->key)
|
|
|
|
return 1;
|
|
|
|
if (opt1->key && opt2->key) {
|
|
|
|
if (opt1->key->type != opt2->key->type)
|
|
|
|
return -1;
|
|
|
|
if (opt1->key->created.tv_sec != opt2->key->created.tv_sec)
|
|
|
|
return -1;
|
|
|
|
if (opt1->key->created.tv_nsec != opt2->key->created.tv_nsec)
|
|
|
|
return -1;
|
|
|
|
if (opt1->key->len != opt2->key->len)
|
|
|
|
return -1;
|
|
|
|
if (opt1->key->key && !opt2->key->key)
|
|
|
|
return -1;
|
|
|
|
if (!opt1->key->key && opt2->key->key)
|
|
|
|
return 1;
|
|
|
|
if (opt1->key->key && opt2->key->key) {
|
|
|
|
ret = memcmp(opt1->key->key, opt2->key->key, opt1->key->len);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
2010-04-07 06:14:15 +08:00
|
|
|
|
2020-05-22 21:24:53 +08:00
|
|
|
ret = ceph_compare_crush_locs(&opt1->crush_locs, &opt2->crush_locs);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2010-04-07 06:14:15 +08:00
|
|
|
/* any matching mon ip implies a match */
|
|
|
|
for (i = 0; i < opt1->num_mon; i++) {
|
|
|
|
if (ceph_monmap_contains(client->monc.monmap,
|
|
|
|
&opt1->mon_addr[i]))
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ceph_compare_options);
|
|
|
|
|
2021-07-14 18:05:51 +08:00
|
|
|
int ceph_parse_fsid(const char *str, struct ceph_fsid *fsid)
|
2010-04-07 06:14:15 +08:00
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
char tmp[3];
|
|
|
|
int err = -EINVAL;
|
|
|
|
int d;
|
|
|
|
|
2021-07-14 18:05:51 +08:00
|
|
|
dout("%s '%s'\n", __func__, str);
|
2010-04-07 06:14:15 +08:00
|
|
|
tmp[2] = 0;
|
|
|
|
while (*str && i < 16) {
|
|
|
|
if (ispunct(*str)) {
|
|
|
|
str++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!isxdigit(str[0]) || !isxdigit(str[1]))
|
|
|
|
break;
|
|
|
|
tmp[0] = str[0];
|
|
|
|
tmp[1] = str[1];
|
|
|
|
if (sscanf(tmp, "%x", &d) < 1)
|
|
|
|
break;
|
|
|
|
fsid->fsid[i] = d & 0xff;
|
|
|
|
i++;
|
|
|
|
str += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == 16)
|
|
|
|
err = 0;
|
2021-07-14 18:05:51 +08:00
|
|
|
dout("%s ret %d got fsid %pU\n", __func__, err, fsid);
|
2010-04-07 06:14:15 +08:00
|
|
|
return err;
|
|
|
|
}
|
2021-07-14 18:05:51 +08:00
|
|
|
EXPORT_SYMBOL(ceph_parse_fsid);
|
2010-04-07 06:14:15 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ceph options
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
Opt_osdkeepalivetimeout,
|
|
|
|
Opt_mount_timeout,
|
|
|
|
Opt_osd_idle_ttl,
|
2017-02-13 00:11:07 +08:00
|
|
|
Opt_osd_request_timeout,
|
2010-04-07 06:14:15 +08:00
|
|
|
/* int args above */
|
|
|
|
Opt_fsid,
|
|
|
|
Opt_name,
|
|
|
|
Opt_secret,
|
2011-03-26 07:40:48 +08:00
|
|
|
Opt_key,
|
2010-04-07 06:14:15 +08:00
|
|
|
Opt_ip,
|
2020-05-22 21:24:53 +08:00
|
|
|
Opt_crush_location,
|
2020-05-23 17:47:33 +08:00
|
|
|
Opt_read_from_replica,
|
2020-11-19 23:04:58 +08:00
|
|
|
Opt_ms_mode,
|
2010-04-07 06:14:15 +08:00
|
|
|
/* string args above */
|
2012-02-15 21:43:54 +08:00
|
|
|
Opt_share,
|
|
|
|
Opt_crc,
|
2014-11-11 16:30:55 +08:00
|
|
|
Opt_cephx_require_signatures,
|
2015-10-29 06:52:06 +08:00
|
|
|
Opt_cephx_sign_messages,
|
2015-01-23 19:11:25 +08:00
|
|
|
Opt_tcp_nodelay,
|
2018-12-18 17:31:48 +08:00
|
|
|
Opt_abort_on_full,
|
2021-12-30 22:13:32 +08:00
|
|
|
Opt_rxbounce,
|
2010-04-07 06:14:15 +08:00
|
|
|
};
|
|
|
|
|
2020-05-23 17:47:33 +08:00
|
|
|
enum {
|
|
|
|
Opt_read_from_replica_no,
|
|
|
|
Opt_read_from_replica_balance,
|
|
|
|
Opt_read_from_replica_localize,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct constant_table ceph_param_read_from_replica[] = {
|
|
|
|
{"no", Opt_read_from_replica_no},
|
|
|
|
{"balance", Opt_read_from_replica_balance},
|
|
|
|
{"localize", Opt_read_from_replica_localize},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2020-11-19 23:04:58 +08:00
|
|
|
enum ceph_ms_mode {
|
|
|
|
Opt_ms_mode_legacy,
|
|
|
|
Opt_ms_mode_crc,
|
|
|
|
Opt_ms_mode_secure,
|
|
|
|
Opt_ms_mode_prefer_crc,
|
|
|
|
Opt_ms_mode_prefer_secure
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct constant_table ceph_param_ms_mode[] = {
|
|
|
|
{"legacy", Opt_ms_mode_legacy},
|
|
|
|
{"crc", Opt_ms_mode_crc},
|
|
|
|
{"secure", Opt_ms_mode_secure},
|
|
|
|
{"prefer-crc", Opt_ms_mode_prefer_crc},
|
|
|
|
{"prefer-secure", Opt_ms_mode_prefer_secure},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2019-09-07 19:23:15 +08:00
|
|
|
static const struct fs_parameter_spec ceph_parameters[] = {
|
2019-03-26 00:38:32 +08:00
|
|
|
fsparam_flag ("abort_on_full", Opt_abort_on_full),
|
2021-01-22 22:41:14 +08:00
|
|
|
__fsparam (NULL, "cephx_require_signatures", Opt_cephx_require_signatures,
|
|
|
|
fs_param_neg_with_no|fs_param_deprecated, NULL),
|
2019-03-26 00:38:32 +08:00
|
|
|
fsparam_flag_no ("cephx_sign_messages", Opt_cephx_sign_messages),
|
|
|
|
fsparam_flag_no ("crc", Opt_crc),
|
2020-05-22 21:24:53 +08:00
|
|
|
fsparam_string ("crush_location", Opt_crush_location),
|
2019-03-26 00:38:32 +08:00
|
|
|
fsparam_string ("fsid", Opt_fsid),
|
|
|
|
fsparam_string ("ip", Opt_ip),
|
|
|
|
fsparam_string ("key", Opt_key),
|
|
|
|
fsparam_u32 ("mount_timeout", Opt_mount_timeout),
|
|
|
|
fsparam_string ("name", Opt_name),
|
|
|
|
fsparam_u32 ("osd_idle_ttl", Opt_osd_idle_ttl),
|
|
|
|
fsparam_u32 ("osd_request_timeout", Opt_osd_request_timeout),
|
|
|
|
fsparam_u32 ("osdkeepalive", Opt_osdkeepalivetimeout),
|
2020-05-23 17:47:33 +08:00
|
|
|
fsparam_enum ("read_from_replica", Opt_read_from_replica,
|
|
|
|
ceph_param_read_from_replica),
|
2021-12-30 22:13:32 +08:00
|
|
|
fsparam_flag ("rxbounce", Opt_rxbounce),
|
2020-11-19 23:04:58 +08:00
|
|
|
fsparam_enum ("ms_mode", Opt_ms_mode,
|
|
|
|
ceph_param_ms_mode),
|
2019-03-26 00:38:32 +08:00
|
|
|
fsparam_string ("secret", Opt_secret),
|
|
|
|
fsparam_flag_no ("share", Opt_share),
|
|
|
|
fsparam_flag_no ("tcp_nodelay", Opt_tcp_nodelay),
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ceph_options *ceph_alloc_options(void)
|
|
|
|
{
|
|
|
|
struct ceph_options *opt;
|
|
|
|
|
|
|
|
opt = kzalloc(sizeof(*opt), GFP_KERNEL);
|
|
|
|
if (!opt)
|
|
|
|
return NULL;
|
|
|
|
|
2020-05-22 21:24:53 +08:00
|
|
|
opt->crush_locs = RB_ROOT;
|
2019-03-26 00:38:32 +08:00
|
|
|
opt->mon_addr = kcalloc(CEPH_MAX_MON, sizeof(*opt->mon_addr),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!opt->mon_addr) {
|
|
|
|
kfree(opt);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
opt->flags = CEPH_OPT_DEFAULT;
|
|
|
|
opt->osd_keepalive_timeout = CEPH_OSD_KEEPALIVE_DEFAULT;
|
|
|
|
opt->mount_timeout = CEPH_MOUNT_TIMEOUT_DEFAULT;
|
|
|
|
opt->osd_idle_ttl = CEPH_OSD_IDLE_TTL_DEFAULT;
|
|
|
|
opt->osd_request_timeout = CEPH_OSD_REQUEST_TIMEOUT_DEFAULT;
|
2020-06-04 17:12:34 +08:00
|
|
|
opt->read_from_replica = CEPH_READ_FROM_REPLICA_DEFAULT;
|
2020-11-19 23:04:58 +08:00
|
|
|
opt->con_modes[0] = CEPH_CON_MODE_UNKNOWN;
|
|
|
|
opt->con_modes[1] = CEPH_CON_MODE_UNKNOWN;
|
2019-03-26 00:38:32 +08:00
|
|
|
return opt;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ceph_alloc_options);
|
|
|
|
|
2010-04-07 06:14:15 +08:00
|
|
|
void ceph_destroy_options(struct ceph_options *opt)
|
|
|
|
{
|
|
|
|
dout("destroy_options %p\n", opt);
|
2019-03-26 00:38:32 +08:00
|
|
|
if (!opt)
|
|
|
|
return;
|
|
|
|
|
2020-05-22 21:24:53 +08:00
|
|
|
ceph_clear_crush_locs(&opt->crush_locs);
|
2010-04-07 06:14:15 +08:00
|
|
|
kfree(opt->name);
|
2011-03-26 07:32:57 +08:00
|
|
|
if (opt->key) {
|
|
|
|
ceph_crypto_key_destroy(opt->key);
|
|
|
|
kfree(opt->key);
|
|
|
|
}
|
2011-09-13 05:51:53 +08:00
|
|
|
kfree(opt->mon_addr);
|
2010-04-07 06:14:15 +08:00
|
|
|
kfree(opt);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ceph_destroy_options);
|
|
|
|
|
2011-03-26 07:40:48 +08:00
|
|
|
/* get secret from key store */
|
2019-03-26 00:38:32 +08:00
|
|
|
static int get_secret(struct ceph_crypto_key *dst, const char *name,
|
2019-12-21 12:43:32 +08:00
|
|
|
struct p_log *log)
|
2019-03-26 00:38:32 +08:00
|
|
|
{
|
2011-03-26 07:40:48 +08:00
|
|
|
struct key *ukey;
|
|
|
|
int key_err;
|
|
|
|
int err = 0;
|
2011-03-29 05:59:38 +08:00
|
|
|
struct ceph_crypto_key *ckey;
|
2011-03-26 07:40:48 +08:00
|
|
|
|
2011-03-29 05:59:38 +08:00
|
|
|
ukey = request_key(&key_type_ceph, name, NULL);
|
2018-08-07 21:02:34 +08:00
|
|
|
if (IS_ERR(ukey)) {
|
2011-03-26 07:40:48 +08:00
|
|
|
/* request_key errors don't map nicely to mount(2)
|
|
|
|
errors; don't even try, but still printk */
|
|
|
|
key_err = PTR_ERR(ukey);
|
|
|
|
switch (key_err) {
|
|
|
|
case -ENOKEY:
|
2019-12-21 12:43:32 +08:00
|
|
|
error_plog(log, "Failed due to key not found: %s",
|
2019-03-26 00:38:32 +08:00
|
|
|
name);
|
2011-03-26 07:40:48 +08:00
|
|
|
break;
|
|
|
|
case -EKEYEXPIRED:
|
2019-12-21 12:43:32 +08:00
|
|
|
error_plog(log, "Failed due to expired key: %s",
|
2019-03-26 00:38:32 +08:00
|
|
|
name);
|
2011-03-26 07:40:48 +08:00
|
|
|
break;
|
|
|
|
case -EKEYREVOKED:
|
2019-12-21 12:43:32 +08:00
|
|
|
error_plog(log, "Failed due to revoked key: %s",
|
2019-03-26 00:38:32 +08:00
|
|
|
name);
|
2011-03-26 07:40:48 +08:00
|
|
|
break;
|
|
|
|
default:
|
2019-12-21 12:43:32 +08:00
|
|
|
error_plog(log, "Failed due to key error %d: %s",
|
2019-03-26 00:38:32 +08:00
|
|
|
key_err, name);
|
2011-03-26 07:40:48 +08:00
|
|
|
}
|
|
|
|
err = -EPERM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2015-10-21 21:04:48 +08:00
|
|
|
ckey = ukey->payload.data[0];
|
2011-03-29 05:59:38 +08:00
|
|
|
err = ceph_crypto_key_clone(dst, ckey);
|
2011-03-26 07:40:48 +08:00
|
|
|
if (err)
|
|
|
|
goto out_key;
|
|
|
|
/* pass through, err is 0 */
|
|
|
|
|
|
|
|
out_key:
|
|
|
|
key_put(ukey);
|
|
|
|
out:
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2019-03-26 00:38:32 +08:00
|
|
|
int ceph_parse_mon_ips(const char *buf, size_t len, struct ceph_options *opt,
|
2021-07-14 18:05:50 +08:00
|
|
|
struct fc_log *l, char delim)
|
2010-04-07 06:14:15 +08:00
|
|
|
{
|
2019-12-21 13:06:01 +08:00
|
|
|
struct p_log log = {.prefix = "libceph", .log = l};
|
2019-03-26 00:38:32 +08:00
|
|
|
int ret;
|
2010-04-07 06:14:15 +08:00
|
|
|
|
2021-07-14 18:05:50 +08:00
|
|
|
/* ip1[:port1][<delim>ip2[:port2]...] */
|
2019-03-26 00:38:32 +08:00
|
|
|
ret = ceph_parse_ips(buf, buf + len, opt->mon_addr, CEPH_MAX_MON,
|
2021-07-14 18:05:50 +08:00
|
|
|
&opt->num_mon, delim);
|
2019-03-26 00:38:32 +08:00
|
|
|
if (ret) {
|
2019-12-21 12:43:32 +08:00
|
|
|
error_plog(&log, "Failed to parse monitor IPs: %d", ret);
|
2019-03-26 00:38:32 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2010-04-07 06:14:15 +08:00
|
|
|
|
2019-03-26 00:38:32 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ceph_parse_mon_ips);
|
|
|
|
|
|
|
|
int ceph_parse_param(struct fs_parameter *param, struct ceph_options *opt,
|
2019-12-21 13:06:01 +08:00
|
|
|
struct fc_log *l)
|
2019-03-26 00:38:32 +08:00
|
|
|
{
|
|
|
|
struct fs_parse_result result;
|
|
|
|
int token, err;
|
2019-12-21 13:06:01 +08:00
|
|
|
struct p_log log = {.prefix = "libceph", .log = l};
|
2019-03-26 00:38:32 +08:00
|
|
|
|
2019-09-07 19:23:15 +08:00
|
|
|
token = __fs_parse(&log, ceph_parameters, param, &result);
|
2019-03-26 00:38:32 +08:00
|
|
|
dout("%s fs_parse '%s' token %d\n", __func__, param->key, token);
|
|
|
|
if (token < 0)
|
|
|
|
return token;
|
|
|
|
|
|
|
|
switch (token) {
|
|
|
|
case Opt_ip:
|
|
|
|
err = ceph_parse_ips(param->string,
|
|
|
|
param->string + param->size,
|
2021-07-14 18:05:50 +08:00
|
|
|
&opt->my_addr, 1, NULL, ',');
|
2019-03-26 00:38:32 +08:00
|
|
|
if (err) {
|
2019-12-21 12:43:32 +08:00
|
|
|
error_plog(&log, "Failed to parse ip: %d", err);
|
2019-03-26 00:38:32 +08:00
|
|
|
return err;
|
2010-04-07 06:14:15 +08:00
|
|
|
}
|
2019-03-26 00:38:32 +08:00
|
|
|
opt->flags |= CEPH_OPT_MYIP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Opt_fsid:
|
2021-07-14 18:05:51 +08:00
|
|
|
err = ceph_parse_fsid(param->string, &opt->fsid);
|
2019-03-26 00:38:32 +08:00
|
|
|
if (err) {
|
2019-12-21 12:43:32 +08:00
|
|
|
error_plog(&log, "Failed to parse fsid: %d", err);
|
2019-03-26 00:38:32 +08:00
|
|
|
return err;
|
2010-04-07 06:14:15 +08:00
|
|
|
}
|
2019-03-26 00:38:32 +08:00
|
|
|
opt->flags |= CEPH_OPT_FSID;
|
|
|
|
break;
|
|
|
|
case Opt_name:
|
|
|
|
kfree(opt->name);
|
|
|
|
opt->name = param->string;
|
|
|
|
param->string = NULL;
|
|
|
|
break;
|
|
|
|
case Opt_secret:
|
|
|
|
ceph_crypto_key_destroy(opt->key);
|
|
|
|
kfree(opt->key);
|
2010-04-07 06:14:15 +08:00
|
|
|
|
2019-03-26 00:38:32 +08:00
|
|
|
opt->key = kzalloc(sizeof(*opt->key), GFP_KERNEL);
|
|
|
|
if (!opt->key)
|
|
|
|
return -ENOMEM;
|
|
|
|
err = ceph_crypto_key_unarmor(opt->key, param->string);
|
|
|
|
if (err) {
|
2019-12-21 12:43:32 +08:00
|
|
|
error_plog(&log, "Failed to parse secret: %d", err);
|
2019-03-26 00:38:32 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Opt_key:
|
|
|
|
ceph_crypto_key_destroy(opt->key);
|
|
|
|
kfree(opt->key);
|
2010-04-07 06:14:15 +08:00
|
|
|
|
2019-03-26 00:38:32 +08:00
|
|
|
opt->key = kzalloc(sizeof(*opt->key), GFP_KERNEL);
|
|
|
|
if (!opt->key)
|
|
|
|
return -ENOMEM;
|
2019-12-21 12:43:32 +08:00
|
|
|
return get_secret(opt->key, param->string, &log);
|
2020-05-22 21:24:53 +08:00
|
|
|
case Opt_crush_location:
|
|
|
|
ceph_clear_crush_locs(&opt->crush_locs);
|
|
|
|
err = ceph_parse_crush_location(param->string,
|
|
|
|
&opt->crush_locs);
|
|
|
|
if (err) {
|
|
|
|
error_plog(&log, "Failed to parse CRUSH location: %d",
|
|
|
|
err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
break;
|
2020-05-23 17:47:33 +08:00
|
|
|
case Opt_read_from_replica:
|
|
|
|
switch (result.uint_32) {
|
|
|
|
case Opt_read_from_replica_no:
|
2020-06-04 17:12:34 +08:00
|
|
|
opt->read_from_replica = 0;
|
2020-05-23 17:47:33 +08:00
|
|
|
break;
|
|
|
|
case Opt_read_from_replica_balance:
|
2020-06-04 17:12:34 +08:00
|
|
|
opt->read_from_replica = CEPH_OSD_FLAG_BALANCE_READS;
|
2020-05-23 17:47:33 +08:00
|
|
|
break;
|
|
|
|
case Opt_read_from_replica_localize:
|
2020-06-04 17:12:34 +08:00
|
|
|
opt->read_from_replica = CEPH_OSD_FLAG_LOCALIZE_READS;
|
2020-05-23 17:47:33 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
break;
|
2020-11-19 23:04:58 +08:00
|
|
|
case Opt_ms_mode:
|
|
|
|
switch (result.uint_32) {
|
|
|
|
case Opt_ms_mode_legacy:
|
|
|
|
opt->con_modes[0] = CEPH_CON_MODE_UNKNOWN;
|
|
|
|
opt->con_modes[1] = CEPH_CON_MODE_UNKNOWN;
|
|
|
|
break;
|
|
|
|
case Opt_ms_mode_crc:
|
|
|
|
opt->con_modes[0] = CEPH_CON_MODE_CRC;
|
|
|
|
opt->con_modes[1] = CEPH_CON_MODE_UNKNOWN;
|
|
|
|
break;
|
|
|
|
case Opt_ms_mode_secure:
|
|
|
|
opt->con_modes[0] = CEPH_CON_MODE_SECURE;
|
|
|
|
opt->con_modes[1] = CEPH_CON_MODE_UNKNOWN;
|
|
|
|
break;
|
|
|
|
case Opt_ms_mode_prefer_crc:
|
|
|
|
opt->con_modes[0] = CEPH_CON_MODE_CRC;
|
|
|
|
opt->con_modes[1] = CEPH_CON_MODE_SECURE;
|
|
|
|
break;
|
|
|
|
case Opt_ms_mode_prefer_secure:
|
|
|
|
opt->con_modes[0] = CEPH_CON_MODE_SECURE;
|
|
|
|
opt->con_modes[1] = CEPH_CON_MODE_CRC;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
BUG();
|
|
|
|
}
|
|
|
|
break;
|
2019-03-26 00:38:32 +08:00
|
|
|
|
|
|
|
case Opt_osdkeepalivetimeout:
|
|
|
|
/* 0 isn't well defined right now, reject it */
|
|
|
|
if (result.uint_32 < 1 || result.uint_32 > INT_MAX / 1000)
|
|
|
|
goto out_of_range;
|
|
|
|
opt->osd_keepalive_timeout =
|
|
|
|
msecs_to_jiffies(result.uint_32 * 1000);
|
|
|
|
break;
|
|
|
|
case Opt_osd_idle_ttl:
|
|
|
|
/* 0 isn't well defined right now, reject it */
|
|
|
|
if (result.uint_32 < 1 || result.uint_32 > INT_MAX / 1000)
|
|
|
|
goto out_of_range;
|
|
|
|
opt->osd_idle_ttl = msecs_to_jiffies(result.uint_32 * 1000);
|
|
|
|
break;
|
|
|
|
case Opt_mount_timeout:
|
|
|
|
/* 0 is "wait forever" (i.e. infinite timeout) */
|
|
|
|
if (result.uint_32 > INT_MAX / 1000)
|
|
|
|
goto out_of_range;
|
|
|
|
opt->mount_timeout = msecs_to_jiffies(result.uint_32 * 1000);
|
|
|
|
break;
|
|
|
|
case Opt_osd_request_timeout:
|
|
|
|
/* 0 is "wait forever" (i.e. infinite timeout) */
|
|
|
|
if (result.uint_32 > INT_MAX / 1000)
|
|
|
|
goto out_of_range;
|
|
|
|
opt->osd_request_timeout =
|
|
|
|
msecs_to_jiffies(result.uint_32 * 1000);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Opt_share:
|
|
|
|
if (!result.negated)
|
2012-02-15 21:43:54 +08:00
|
|
|
opt->flags &= ~CEPH_OPT_NOSHARE;
|
2019-03-26 00:38:32 +08:00
|
|
|
else
|
2010-04-07 06:14:15 +08:00
|
|
|
opt->flags |= CEPH_OPT_NOSHARE;
|
2019-03-26 00:38:32 +08:00
|
|
|
break;
|
|
|
|
case Opt_crc:
|
|
|
|
if (!result.negated)
|
2012-02-15 21:43:54 +08:00
|
|
|
opt->flags &= ~CEPH_OPT_NOCRC;
|
2019-03-26 00:38:32 +08:00
|
|
|
else
|
2010-04-07 06:14:15 +08:00
|
|
|
opt->flags |= CEPH_OPT_NOCRC;
|
2019-03-26 00:38:32 +08:00
|
|
|
break;
|
|
|
|
case Opt_cephx_require_signatures:
|
|
|
|
if (!result.negated)
|
2021-01-22 22:41:14 +08:00
|
|
|
warn_plog(&log, "Ignoring cephx_require_signatures");
|
2019-03-26 00:38:32 +08:00
|
|
|
else
|
2021-01-22 22:41:14 +08:00
|
|
|
warn_plog(&log, "Ignoring nocephx_require_signatures, use nocephx_sign_messages");
|
2019-03-26 00:38:32 +08:00
|
|
|
break;
|
|
|
|
case Opt_cephx_sign_messages:
|
|
|
|
if (!result.negated)
|
2015-10-29 06:52:06 +08:00
|
|
|
opt->flags &= ~CEPH_OPT_NOMSGSIGN;
|
2019-03-26 00:38:32 +08:00
|
|
|
else
|
2015-10-29 06:52:06 +08:00
|
|
|
opt->flags |= CEPH_OPT_NOMSGSIGN;
|
2019-03-26 00:38:32 +08:00
|
|
|
break;
|
|
|
|
case Opt_tcp_nodelay:
|
|
|
|
if (!result.negated)
|
2015-01-23 19:11:25 +08:00
|
|
|
opt->flags |= CEPH_OPT_TCP_NODELAY;
|
2019-03-26 00:38:32 +08:00
|
|
|
else
|
2015-01-23 19:11:25 +08:00
|
|
|
opt->flags &= ~CEPH_OPT_TCP_NODELAY;
|
2019-03-26 00:38:32 +08:00
|
|
|
break;
|
2015-01-23 19:11:25 +08:00
|
|
|
|
2019-03-26 00:38:32 +08:00
|
|
|
case Opt_abort_on_full:
|
|
|
|
opt->flags |= CEPH_OPT_ABORT_ON_FULL;
|
|
|
|
break;
|
2021-12-30 22:13:32 +08:00
|
|
|
case Opt_rxbounce:
|
|
|
|
opt->flags |= CEPH_OPT_RXBOUNCE;
|
|
|
|
break;
|
2018-12-18 17:31:48 +08:00
|
|
|
|
2019-03-26 00:38:32 +08:00
|
|
|
default:
|
|
|
|
BUG();
|
2010-04-07 06:14:15 +08:00
|
|
|
}
|
|
|
|
|
2019-03-26 00:38:32 +08:00
|
|
|
return 0;
|
2010-04-07 06:14:15 +08:00
|
|
|
|
2019-03-26 00:38:32 +08:00
|
|
|
out_of_range:
|
2019-12-21 12:43:32 +08:00
|
|
|
return inval_plog(&log, "%s out of range", param->key);
|
2010-04-07 06:14:15 +08:00
|
|
|
}
|
2019-03-26 00:38:32 +08:00
|
|
|
EXPORT_SYMBOL(ceph_parse_param);
|
2010-04-07 06:14:15 +08:00
|
|
|
|
2018-12-18 17:31:48 +08:00
|
|
|
int ceph_print_client_options(struct seq_file *m, struct ceph_client *client,
|
|
|
|
bool show_all)
|
2015-03-26 02:02:16 +08:00
|
|
|
{
|
|
|
|
struct ceph_options *opt = client->options;
|
|
|
|
size_t pos = m->count;
|
2020-05-22 21:24:53 +08:00
|
|
|
struct rb_node *n;
|
2015-03-26 02:02:16 +08:00
|
|
|
|
fs: create and use seq_show_option for escaping
Many file systems that implement the show_options hook fail to correctly
escape their output which could lead to unescaped characters (e.g. new
lines) leaking into /proc/mounts and /proc/[pid]/mountinfo files. This
could lead to confusion, spoofed entries (resulting in things like
systemd issuing false d-bus "mount" notifications), and who knows what
else. This looks like it would only be the root user stepping on
themselves, but it's possible weird things could happen in containers or
in other situations with delegated mount privileges.
Here's an example using overlay with setuid fusermount trusting the
contents of /proc/mounts (via the /etc/mtab symlink). Imagine the use
of "sudo" is something more sneaky:
$ BASE="ovl"
$ MNT="$BASE/mnt"
$ LOW="$BASE/lower"
$ UP="$BASE/upper"
$ WORK="$BASE/work/ 0 0
none /proc fuse.pwn user_id=1000"
$ mkdir -p "$LOW" "$UP" "$WORK"
$ sudo mount -t overlay -o "lowerdir=$LOW,upperdir=$UP,workdir=$WORK" none /mnt
$ cat /proc/mounts
none /root/ovl/mnt overlay rw,relatime,lowerdir=ovl/lower,upperdir=ovl/upper,workdir=ovl/work/ 0 0
none /proc fuse.pwn user_id=1000 0 0
$ fusermount -u /proc
$ cat /proc/mounts
cat: /proc/mounts: No such file or directory
This fixes the problem by adding new seq_show_option and
seq_show_option_n helpers, and updating the vulnerable show_option
handlers to use them as needed. Some, like SELinux, need to be open
coded due to unusual existing escape mechanisms.
[akpm@linux-foundation.org: add lost chunk, per Kees]
[keescook@chromium.org: seq_show_option should be using const parameters]
Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Serge Hallyn <serge.hallyn@canonical.com>
Acked-by: Jan Kara <jack@suse.com>
Acked-by: Paul Moore <paul@paul-moore.com>
Cc: J. R. Okajima <hooanon05g@gmail.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2015-09-05 06:44:57 +08:00
|
|
|
if (opt->name) {
|
|
|
|
seq_puts(m, "name=");
|
|
|
|
seq_escape(m, opt->name, ", \t\n\\");
|
|
|
|
seq_putc(m, ',');
|
|
|
|
}
|
2015-03-26 02:02:16 +08:00
|
|
|
if (opt->key)
|
|
|
|
seq_puts(m, "secret=<hidden>,");
|
|
|
|
|
2020-05-22 21:24:53 +08:00
|
|
|
if (!RB_EMPTY_ROOT(&opt->crush_locs)) {
|
|
|
|
seq_puts(m, "crush_location=");
|
|
|
|
for (n = rb_first(&opt->crush_locs); ; ) {
|
|
|
|
struct crush_loc_node *loc =
|
|
|
|
rb_entry(n, struct crush_loc_node, cl_node);
|
|
|
|
|
|
|
|
seq_printf(m, "%s:%s", loc->cl_loc.cl_type_name,
|
|
|
|
loc->cl_loc.cl_name);
|
|
|
|
n = rb_next(n);
|
|
|
|
if (!n)
|
|
|
|
break;
|
|
|
|
|
|
|
|
seq_putc(m, '|');
|
|
|
|
}
|
|
|
|
seq_putc(m, ',');
|
|
|
|
}
|
2020-06-04 17:12:34 +08:00
|
|
|
if (opt->read_from_replica == CEPH_OSD_FLAG_BALANCE_READS) {
|
2020-05-23 17:47:33 +08:00
|
|
|
seq_puts(m, "read_from_replica=balance,");
|
2020-06-04 17:12:34 +08:00
|
|
|
} else if (opt->read_from_replica == CEPH_OSD_FLAG_LOCALIZE_READS) {
|
2020-05-23 17:47:33 +08:00
|
|
|
seq_puts(m, "read_from_replica=localize,");
|
|
|
|
}
|
2020-11-19 23:04:58 +08:00
|
|
|
if (opt->con_modes[0] != CEPH_CON_MODE_UNKNOWN) {
|
|
|
|
if (opt->con_modes[0] == CEPH_CON_MODE_CRC &&
|
|
|
|
opt->con_modes[1] == CEPH_CON_MODE_UNKNOWN) {
|
|
|
|
seq_puts(m, "ms_mode=crc,");
|
|
|
|
} else if (opt->con_modes[0] == CEPH_CON_MODE_SECURE &&
|
|
|
|
opt->con_modes[1] == CEPH_CON_MODE_UNKNOWN) {
|
|
|
|
seq_puts(m, "ms_mode=secure,");
|
|
|
|
} else if (opt->con_modes[0] == CEPH_CON_MODE_CRC &&
|
|
|
|
opt->con_modes[1] == CEPH_CON_MODE_SECURE) {
|
|
|
|
seq_puts(m, "ms_mode=prefer-crc,");
|
|
|
|
} else if (opt->con_modes[0] == CEPH_CON_MODE_SECURE &&
|
|
|
|
opt->con_modes[1] == CEPH_CON_MODE_CRC) {
|
|
|
|
seq_puts(m, "ms_mode=prefer-secure,");
|
|
|
|
}
|
|
|
|
}
|
2020-05-22 21:24:53 +08:00
|
|
|
|
2015-03-26 02:02:16 +08:00
|
|
|
if (opt->flags & CEPH_OPT_FSID)
|
|
|
|
seq_printf(m, "fsid=%pU,", &opt->fsid);
|
|
|
|
if (opt->flags & CEPH_OPT_NOSHARE)
|
|
|
|
seq_puts(m, "noshare,");
|
|
|
|
if (opt->flags & CEPH_OPT_NOCRC)
|
|
|
|
seq_puts(m, "nocrc,");
|
2015-10-29 06:52:06 +08:00
|
|
|
if (opt->flags & CEPH_OPT_NOMSGSIGN)
|
|
|
|
seq_puts(m, "nocephx_sign_messages,");
|
2015-03-26 02:02:16 +08:00
|
|
|
if ((opt->flags & CEPH_OPT_TCP_NODELAY) == 0)
|
|
|
|
seq_puts(m, "notcp_nodelay,");
|
2018-12-18 17:31:48 +08:00
|
|
|
if (show_all && (opt->flags & CEPH_OPT_ABORT_ON_FULL))
|
|
|
|
seq_puts(m, "abort_on_full,");
|
2021-12-30 22:13:32 +08:00
|
|
|
if (opt->flags & CEPH_OPT_RXBOUNCE)
|
|
|
|
seq_puts(m, "rxbounce,");
|
2015-03-26 02:02:16 +08:00
|
|
|
|
|
|
|
if (opt->mount_timeout != CEPH_MOUNT_TIMEOUT_DEFAULT)
|
2015-05-15 17:02:17 +08:00
|
|
|
seq_printf(m, "mount_timeout=%d,",
|
|
|
|
jiffies_to_msecs(opt->mount_timeout) / 1000);
|
2015-03-26 02:02:16 +08:00
|
|
|
if (opt->osd_idle_ttl != CEPH_OSD_IDLE_TTL_DEFAULT)
|
2015-05-15 17:02:17 +08:00
|
|
|
seq_printf(m, "osd_idle_ttl=%d,",
|
|
|
|
jiffies_to_msecs(opt->osd_idle_ttl) / 1000);
|
2015-03-26 02:02:16 +08:00
|
|
|
if (opt->osd_keepalive_timeout != CEPH_OSD_KEEPALIVE_DEFAULT)
|
|
|
|
seq_printf(m, "osdkeepalivetimeout=%d,",
|
2015-05-15 17:02:17 +08:00
|
|
|
jiffies_to_msecs(opt->osd_keepalive_timeout) / 1000);
|
2017-02-13 00:11:07 +08:00
|
|
|
if (opt->osd_request_timeout != CEPH_OSD_REQUEST_TIMEOUT_DEFAULT)
|
|
|
|
seq_printf(m, "osd_request_timeout=%d,",
|
|
|
|
jiffies_to_msecs(opt->osd_request_timeout) / 1000);
|
2015-03-26 02:02:16 +08:00
|
|
|
|
|
|
|
/* drop redundant comma */
|
|
|
|
if (m->count != pos)
|
|
|
|
m->count--;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ceph_print_client_options);
|
|
|
|
|
2016-08-19 00:38:43 +08:00
|
|
|
struct ceph_entity_addr *ceph_client_addr(struct ceph_client *client)
|
|
|
|
{
|
|
|
|
return &client->msgr.inst.addr;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ceph_client_addr);
|
|
|
|
|
2016-08-12 20:59:58 +08:00
|
|
|
u64 ceph_client_gid(struct ceph_client *client)
|
2010-04-07 06:14:15 +08:00
|
|
|
{
|
|
|
|
return client->monc.auth->global_id;
|
|
|
|
}
|
2016-08-12 20:59:58 +08:00
|
|
|
EXPORT_SYMBOL(ceph_client_gid);
|
2010-04-07 06:14:15 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* create a fresh client instance
|
|
|
|
*/
|
2017-03-04 01:16:07 +08:00
|
|
|
struct ceph_client *ceph_create_client(struct ceph_options *opt, void *private)
|
2010-04-07 06:14:15 +08:00
|
|
|
{
|
|
|
|
struct ceph_client *client;
|
2011-08-10 00:41:59 +08:00
|
|
|
struct ceph_entity_addr *myaddr = NULL;
|
2017-06-08 10:44:54 +08:00
|
|
|
int err;
|
|
|
|
|
|
|
|
err = wait_for_random_bytes();
|
|
|
|
if (err < 0)
|
|
|
|
return ERR_PTR(err);
|
2010-04-07 06:14:15 +08:00
|
|
|
|
|
|
|
client = kzalloc(sizeof(*client), GFP_KERNEL);
|
|
|
|
if (client == NULL)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
client->private = private;
|
|
|
|
client->options = opt;
|
|
|
|
|
|
|
|
mutex_init(&client->mount_mutex);
|
|
|
|
init_waitqueue_head(&client->auth_wq);
|
|
|
|
client->auth_err = 0;
|
|
|
|
|
|
|
|
client->extra_mon_dispatch = NULL;
|
2017-03-04 01:16:07 +08:00
|
|
|
client->supported_features = CEPH_FEATURES_SUPPORTED_DEFAULT;
|
|
|
|
client->required_features = CEPH_FEATURES_REQUIRED_DEFAULT;
|
|
|
|
|
2021-01-22 22:41:14 +08:00
|
|
|
if (!ceph_test_opt(client, NOMSGSIGN))
|
2017-03-04 01:16:07 +08:00
|
|
|
client->required_features |= CEPH_FEATURE_MSG_AUTH;
|
2011-08-10 00:41:59 +08:00
|
|
|
|
|
|
|
/* msgr */
|
|
|
|
if (ceph_test_opt(client, MYIP))
|
|
|
|
myaddr = &client->options->my_addr;
|
2015-01-23 19:11:25 +08:00
|
|
|
|
2015-10-29 06:50:58 +08:00
|
|
|
ceph_messenger_init(&client->msgr, myaddr);
|
2010-04-07 06:14:15 +08:00
|
|
|
|
|
|
|
/* subsystems */
|
|
|
|
err = ceph_monc_init(&client->monc, client);
|
|
|
|
if (err < 0)
|
2012-05-27 12:26:43 +08:00
|
|
|
goto fail;
|
2010-04-07 06:14:15 +08:00
|
|
|
err = ceph_osdc_init(&client->osdc, client);
|
|
|
|
if (err < 0)
|
|
|
|
goto fail_monc;
|
|
|
|
|
|
|
|
return client;
|
|
|
|
|
|
|
|
fail_monc:
|
|
|
|
ceph_monc_stop(&client->monc);
|
|
|
|
fail:
|
2015-06-25 22:47:45 +08:00
|
|
|
ceph_messenger_fini(&client->msgr);
|
2010-04-07 06:14:15 +08:00
|
|
|
kfree(client);
|
|
|
|
return ERR_PTR(err);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ceph_create_client);
|
|
|
|
|
|
|
|
void ceph_destroy_client(struct ceph_client *client)
|
|
|
|
{
|
|
|
|
dout("destroy_client %p\n", client);
|
|
|
|
|
2012-07-09 10:50:33 +08:00
|
|
|
atomic_set(&client->msgr.stopping, 1);
|
|
|
|
|
2010-04-07 06:14:15 +08:00
|
|
|
/* unmount */
|
|
|
|
ceph_osdc_stop(&client->osdc);
|
|
|
|
ceph_monc_stop(&client->monc);
|
2015-06-25 22:47:45 +08:00
|
|
|
ceph_messenger_fini(&client->msgr);
|
2010-04-07 06:14:15 +08:00
|
|
|
|
|
|
|
ceph_debugfs_client_cleanup(client);
|
|
|
|
|
|
|
|
ceph_destroy_options(client->options);
|
|
|
|
|
|
|
|
kfree(client);
|
|
|
|
dout("destroy_client %p done\n", client);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ceph_destroy_client);
|
|
|
|
|
2019-07-25 20:16:39 +08:00
|
|
|
void ceph_reset_client_addr(struct ceph_client *client)
|
|
|
|
{
|
|
|
|
ceph_messenger_reset_nonce(&client->msgr);
|
|
|
|
ceph_monc_reopen_session(&client->monc);
|
|
|
|
ceph_osdc_reopen_osds(&client->osdc);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ceph_reset_client_addr);
|
|
|
|
|
2010-04-07 06:14:15 +08:00
|
|
|
/*
|
|
|
|
* true if we have the mon map (and have thus joined the cluster)
|
|
|
|
*/
|
2016-03-25 17:18:39 +08:00
|
|
|
static bool have_mon_and_osd_map(struct ceph_client *client)
|
2010-04-07 06:14:15 +08:00
|
|
|
{
|
|
|
|
return client->monc.monmap && client->monc.monmap->epoch &&
|
|
|
|
client->osdc.osdmap && client->osdc.osdmap->epoch;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* mount: join the ceph cluster, and open root directory.
|
|
|
|
*/
|
|
|
|
int __ceph_open_session(struct ceph_client *client, unsigned long started)
|
|
|
|
{
|
2015-05-15 17:02:17 +08:00
|
|
|
unsigned long timeout = client->options->mount_timeout;
|
2015-05-19 17:03:33 +08:00
|
|
|
long err;
|
2010-04-07 06:14:15 +08:00
|
|
|
|
|
|
|
/* open session, and wait for mon and osd maps */
|
|
|
|
err = ceph_monc_open_session(&client->monc);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
while (!have_mon_and_osd_map(client)) {
|
|
|
|
if (timeout && time_after_eq(jiffies, started + timeout))
|
2015-05-19 17:03:33 +08:00
|
|
|
return -ETIMEDOUT;
|
2010-04-07 06:14:15 +08:00
|
|
|
|
|
|
|
/* wait */
|
|
|
|
dout("mount waiting for mon_map\n");
|
|
|
|
err = wait_event_interruptible_timeout(client->auth_wq,
|
|
|
|
have_mon_and_osd_map(client) || (client->auth_err < 0),
|
2015-05-15 17:02:17 +08:00
|
|
|
ceph_timeout_jiffies(timeout));
|
2015-05-19 17:03:33 +08:00
|
|
|
if (err < 0)
|
2010-04-07 06:14:15 +08:00
|
|
|
return err;
|
|
|
|
if (client->auth_err < 0)
|
|
|
|
return client->auth_err;
|
|
|
|
}
|
|
|
|
|
2016-08-12 20:59:58 +08:00
|
|
|
pr_info("client%llu fsid %pU\n", ceph_client_gid(client),
|
|
|
|
&client->fsid);
|
2016-01-06 17:56:21 +08:00
|
|
|
ceph_debugfs_client_init(client);
|
|
|
|
|
2010-04-07 06:14:15 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(__ceph_open_session);
|
|
|
|
|
|
|
|
int ceph_open_session(struct ceph_client *client)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
unsigned long started = jiffies; /* note the start time */
|
|
|
|
|
|
|
|
dout("open_session start\n");
|
|
|
|
mutex_lock(&client->mount_mutex);
|
|
|
|
|
|
|
|
ret = __ceph_open_session(client, started);
|
|
|
|
|
|
|
|
mutex_unlock(&client->mount_mutex);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ceph_open_session);
|
|
|
|
|
2019-03-20 16:46:58 +08:00
|
|
|
int ceph_wait_for_latest_osdmap(struct ceph_client *client,
|
|
|
|
unsigned long timeout)
|
|
|
|
{
|
|
|
|
u64 newest_epoch;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = ceph_monc_get_version(&client->monc, "osdmap", &newest_epoch);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (client->osdc.osdmap->epoch >= newest_epoch)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ceph_osdc_maybe_request_map(&client->osdc);
|
|
|
|
return ceph_monc_wait_osdmap(&client->monc, newest_epoch, timeout);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(ceph_wait_for_latest_osdmap);
|
2010-04-07 06:14:15 +08:00
|
|
|
|
|
|
|
static int __init init_ceph_lib(void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
2019-06-12 22:55:38 +08:00
|
|
|
ceph_debugfs_init();
|
2010-04-07 06:14:15 +08:00
|
|
|
|
2011-03-29 05:59:38 +08:00
|
|
|
ret = ceph_crypto_init();
|
2010-04-07 06:14:15 +08:00
|
|
|
if (ret < 0)
|
|
|
|
goto out_debugfs;
|
|
|
|
|
2011-03-29 05:59:38 +08:00
|
|
|
ret = ceph_msgr_init();
|
|
|
|
if (ret < 0)
|
|
|
|
goto out_crypto;
|
|
|
|
|
2013-05-02 01:43:04 +08:00
|
|
|
ret = ceph_osdc_setup();
|
|
|
|
if (ret < 0)
|
|
|
|
goto out_msgr;
|
|
|
|
|
2013-02-24 02:41:09 +08:00
|
|
|
pr_info("loaded (mon/osd proto %d/%d)\n",
|
|
|
|
CEPH_MONC_PROTOCOL, CEPH_OSDC_PROTOCOL);
|
2010-04-07 06:14:15 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2013-05-02 01:43:04 +08:00
|
|
|
out_msgr:
|
|
|
|
ceph_msgr_exit();
|
2011-03-29 05:59:38 +08:00
|
|
|
out_crypto:
|
|
|
|
ceph_crypto_shutdown();
|
2010-04-07 06:14:15 +08:00
|
|
|
out_debugfs:
|
|
|
|
ceph_debugfs_cleanup();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit exit_ceph_lib(void)
|
|
|
|
{
|
|
|
|
dout("exit_ceph_lib\n");
|
2016-02-05 15:36:22 +08:00
|
|
|
WARN_ON(!ceph_strings_empty());
|
|
|
|
|
2013-05-02 01:43:04 +08:00
|
|
|
ceph_osdc_cleanup();
|
2010-04-07 06:14:15 +08:00
|
|
|
ceph_msgr_exit();
|
2011-03-29 05:59:38 +08:00
|
|
|
ceph_crypto_shutdown();
|
2010-04-07 06:14:15 +08:00
|
|
|
ceph_debugfs_cleanup();
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(init_ceph_lib);
|
|
|
|
module_exit(exit_ceph_lib);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Sage Weil <sage@newdream.net>");
|
|
|
|
MODULE_AUTHOR("Yehuda Sadeh <yehuda@hq.newdream.net>");
|
|
|
|
MODULE_AUTHOR("Patience Warnick <patience@newdream.net>");
|
2015-06-10 21:13:25 +08:00
|
|
|
MODULE_DESCRIPTION("Ceph core library");
|
2010-04-07 06:14:15 +08:00
|
|
|
MODULE_LICENSE("GPL");
|