mirror of
https://gitee.com/bianbu-linux/linux-6.6
synced 2025-04-24 14:07:52 -04:00
libceph: generalize addr/ip parsing based on delimiter
... and remove hardcoded function name in ceph_parse_ips(). [ idryomov: delim parameter, drop CEPH_ADDR_PARSE_DEFAULT_DELIM ] Signed-off-by: Venky Shankar <vshankar@redhat.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
This commit is contained in:
parent
df0cc57e05
commit
2d7c86a8f9
6 changed files with 17 additions and 16 deletions
|
@ -6497,7 +6497,8 @@ static int rbd_add_parse_args(const char *buf,
|
||||||
pctx.opts->exclusive = RBD_EXCLUSIVE_DEFAULT;
|
pctx.opts->exclusive = RBD_EXCLUSIVE_DEFAULT;
|
||||||
pctx.opts->trim = RBD_TRIM_DEFAULT;
|
pctx.opts->trim = RBD_TRIM_DEFAULT;
|
||||||
|
|
||||||
ret = ceph_parse_mon_ips(mon_addrs, mon_addrs_size, pctx.copts, NULL);
|
ret = ceph_parse_mon_ips(mon_addrs, mon_addrs_size, pctx.copts, NULL,
|
||||||
|
',');
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out_err;
|
goto out_err;
|
||||||
|
|
||||||
|
|
|
@ -272,7 +272,7 @@ static int ceph_parse_source(struct fs_parameter *param, struct fs_context *fc)
|
||||||
dout("server path '%s'\n", fsopt->server_path);
|
dout("server path '%s'\n", fsopt->server_path);
|
||||||
|
|
||||||
ret = ceph_parse_mon_ips(param->string, dev_name_end - dev_name,
|
ret = ceph_parse_mon_ips(param->string, dev_name_end - dev_name,
|
||||||
pctx->copts, fc->log.log);
|
pctx->copts, fc->log.log, ',');
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
|
|
@ -301,7 +301,7 @@ struct fs_parameter;
|
||||||
struct fc_log;
|
struct fc_log;
|
||||||
struct ceph_options *ceph_alloc_options(void);
|
struct ceph_options *ceph_alloc_options(void);
|
||||||
int ceph_parse_mon_ips(const char *buf, size_t len, struct ceph_options *opt,
|
int ceph_parse_mon_ips(const char *buf, size_t len, struct ceph_options *opt,
|
||||||
struct fc_log *l);
|
struct fc_log *l, char delim);
|
||||||
int ceph_parse_param(struct fs_parameter *param, struct ceph_options *opt,
|
int ceph_parse_param(struct fs_parameter *param, struct ceph_options *opt,
|
||||||
struct fc_log *l);
|
struct fc_log *l);
|
||||||
int ceph_print_client_options(struct seq_file *m, struct ceph_client *client,
|
int ceph_print_client_options(struct seq_file *m, struct ceph_client *client,
|
||||||
|
|
|
@ -532,7 +532,7 @@ extern const char *ceph_pr_addr(const struct ceph_entity_addr *addr);
|
||||||
|
|
||||||
extern int ceph_parse_ips(const char *c, const char *end,
|
extern int ceph_parse_ips(const char *c, const char *end,
|
||||||
struct ceph_entity_addr *addr,
|
struct ceph_entity_addr *addr,
|
||||||
int max_count, int *count);
|
int max_count, int *count, char delim);
|
||||||
|
|
||||||
extern int ceph_msgr_init(void);
|
extern int ceph_msgr_init(void);
|
||||||
extern void ceph_msgr_exit(void);
|
extern void ceph_msgr_exit(void);
|
||||||
|
|
|
@ -422,14 +422,14 @@ out:
|
||||||
}
|
}
|
||||||
|
|
||||||
int ceph_parse_mon_ips(const char *buf, size_t len, struct ceph_options *opt,
|
int ceph_parse_mon_ips(const char *buf, size_t len, struct ceph_options *opt,
|
||||||
struct fc_log *l)
|
struct fc_log *l, char delim)
|
||||||
{
|
{
|
||||||
struct p_log log = {.prefix = "libceph", .log = l};
|
struct p_log log = {.prefix = "libceph", .log = l};
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* ip1[:port1][,ip2[:port2]...] */
|
/* ip1[:port1][<delim>ip2[:port2]...] */
|
||||||
ret = ceph_parse_ips(buf, buf + len, opt->mon_addr, CEPH_MAX_MON,
|
ret = ceph_parse_ips(buf, buf + len, opt->mon_addr, CEPH_MAX_MON,
|
||||||
&opt->num_mon);
|
&opt->num_mon, delim);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
error_plog(&log, "Failed to parse monitor IPs: %d", ret);
|
error_plog(&log, "Failed to parse monitor IPs: %d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -455,8 +455,7 @@ int ceph_parse_param(struct fs_parameter *param, struct ceph_options *opt,
|
||||||
case Opt_ip:
|
case Opt_ip:
|
||||||
err = ceph_parse_ips(param->string,
|
err = ceph_parse_ips(param->string,
|
||||||
param->string + param->size,
|
param->string + param->size,
|
||||||
&opt->my_addr,
|
&opt->my_addr, 1, NULL, ',');
|
||||||
1, NULL);
|
|
||||||
if (err) {
|
if (err) {
|
||||||
error_plog(&log, "Failed to parse ip: %d", err);
|
error_plog(&log, "Failed to parse ip: %d", err);
|
||||||
return err;
|
return err;
|
||||||
|
|
|
@ -1267,30 +1267,31 @@ static int ceph_parse_server_name(const char *name, size_t namelen,
|
||||||
*/
|
*/
|
||||||
int ceph_parse_ips(const char *c, const char *end,
|
int ceph_parse_ips(const char *c, const char *end,
|
||||||
struct ceph_entity_addr *addr,
|
struct ceph_entity_addr *addr,
|
||||||
int max_count, int *count)
|
int max_count, int *count, char delim)
|
||||||
{
|
{
|
||||||
int i, ret = -EINVAL;
|
int i, ret = -EINVAL;
|
||||||
const char *p = c;
|
const char *p = c;
|
||||||
|
|
||||||
dout("parse_ips on '%.*s'\n", (int)(end-c), c);
|
dout("parse_ips on '%.*s'\n", (int)(end-c), c);
|
||||||
for (i = 0; i < max_count; i++) {
|
for (i = 0; i < max_count; i++) {
|
||||||
|
char cur_delim = delim;
|
||||||
const char *ipend;
|
const char *ipend;
|
||||||
int port;
|
int port;
|
||||||
char delim = ',';
|
|
||||||
|
|
||||||
if (*p == '[') {
|
if (*p == '[') {
|
||||||
delim = ']';
|
cur_delim = ']';
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = ceph_parse_server_name(p, end - p, &addr[i], delim, &ipend);
|
ret = ceph_parse_server_name(p, end - p, &addr[i], cur_delim,
|
||||||
|
&ipend);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto bad;
|
goto bad;
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
|
|
||||||
p = ipend;
|
p = ipend;
|
||||||
|
|
||||||
if (delim == ']') {
|
if (cur_delim == ']') {
|
||||||
if (*p != ']') {
|
if (*p != ']') {
|
||||||
dout("missing matching ']'\n");
|
dout("missing matching ']'\n");
|
||||||
goto bad;
|
goto bad;
|
||||||
|
@ -1326,11 +1327,11 @@ int ceph_parse_ips(const char *c, const char *end,
|
||||||
addr[i].type = CEPH_ENTITY_ADDR_TYPE_LEGACY;
|
addr[i].type = CEPH_ENTITY_ADDR_TYPE_LEGACY;
|
||||||
addr[i].nonce = 0;
|
addr[i].nonce = 0;
|
||||||
|
|
||||||
dout("parse_ips got %s\n", ceph_pr_addr(&addr[i]));
|
dout("%s got %s\n", __func__, ceph_pr_addr(&addr[i]));
|
||||||
|
|
||||||
if (p == end)
|
if (p == end)
|
||||||
break;
|
break;
|
||||||
if (*p != ',')
|
if (*p != delim)
|
||||||
goto bad;
|
goto bad;
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue