Skip to content

Commit 2d7c86a

Browse files
vshankaridryomov
authored andcommitted
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 <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Ilya Dryomov <[email protected]>
1 parent df0cc57 commit 2d7c86a

File tree

6 files changed

+17
-16
lines changed

6 files changed

+17
-16
lines changed

drivers/block/rbd.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6497,7 +6497,8 @@ static int rbd_add_parse_args(const char *buf,
64976497
pctx.opts->exclusive = RBD_EXCLUSIVE_DEFAULT;
64986498
pctx.opts->trim = RBD_TRIM_DEFAULT;
64996499

6500-
ret = ceph_parse_mon_ips(mon_addrs, mon_addrs_size, pctx.copts, NULL);
6500+
ret = ceph_parse_mon_ips(mon_addrs, mon_addrs_size, pctx.copts, NULL,
6501+
',');
65016502
if (ret)
65026503
goto out_err;
65036504

fs/ceph/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ static int ceph_parse_source(struct fs_parameter *param, struct fs_context *fc)
272272
dout("server path '%s'\n", fsopt->server_path);
273273

274274
ret = ceph_parse_mon_ips(param->string, dev_name_end - dev_name,
275-
pctx->copts, fc->log.log);
275+
pctx->copts, fc->log.log, ',');
276276
if (ret)
277277
return ret;
278278

include/linux/ceph/libceph.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ struct fs_parameter;
301301
struct fc_log;
302302
struct ceph_options *ceph_alloc_options(void);
303303
int ceph_parse_mon_ips(const char *buf, size_t len, struct ceph_options *opt,
304-
struct fc_log *l);
304+
struct fc_log *l, char delim);
305305
int ceph_parse_param(struct fs_parameter *param, struct ceph_options *opt,
306306
struct fc_log *l);
307307
int ceph_print_client_options(struct seq_file *m, struct ceph_client *client,

include/linux/ceph/messenger.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ extern const char *ceph_pr_addr(const struct ceph_entity_addr *addr);
532532

533533
extern int ceph_parse_ips(const char *c, const char *end,
534534
struct ceph_entity_addr *addr,
535-
int max_count, int *count);
535+
int max_count, int *count, char delim);
536536

537537
extern int ceph_msgr_init(void);
538538
extern void ceph_msgr_exit(void);

net/ceph/ceph_common.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -422,14 +422,14 @@ static int get_secret(struct ceph_crypto_key *dst, const char *name,
422422
}
423423

424424
int ceph_parse_mon_ips(const char *buf, size_t len, struct ceph_options *opt,
425-
struct fc_log *l)
425+
struct fc_log *l, char delim)
426426
{
427427
struct p_log log = {.prefix = "libceph", .log = l};
428428
int ret;
429429

430-
/* ip1[:port1][,ip2[:port2]...] */
430+
/* ip1[:port1][<delim>ip2[:port2]...] */
431431
ret = ceph_parse_ips(buf, buf + len, opt->mon_addr, CEPH_MAX_MON,
432-
&opt->num_mon);
432+
&opt->num_mon, delim);
433433
if (ret) {
434434
error_plog(&log, "Failed to parse monitor IPs: %d", ret);
435435
return ret;
@@ -455,8 +455,7 @@ int ceph_parse_param(struct fs_parameter *param, struct ceph_options *opt,
455455
case Opt_ip:
456456
err = ceph_parse_ips(param->string,
457457
param->string + param->size,
458-
&opt->my_addr,
459-
1, NULL);
458+
&opt->my_addr, 1, NULL, ',');
460459
if (err) {
461460
error_plog(&log, "Failed to parse ip: %d", err);
462461
return err;

net/ceph/messenger.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1267,30 +1267,31 @@ static int ceph_parse_server_name(const char *name, size_t namelen,
12671267
*/
12681268
int ceph_parse_ips(const char *c, const char *end,
12691269
struct ceph_entity_addr *addr,
1270-
int max_count, int *count)
1270+
int max_count, int *count, char delim)
12711271
{
12721272
int i, ret = -EINVAL;
12731273
const char *p = c;
12741274

12751275
dout("parse_ips on '%.*s'\n", (int)(end-c), c);
12761276
for (i = 0; i < max_count; i++) {
1277+
char cur_delim = delim;
12771278
const char *ipend;
12781279
int port;
1279-
char delim = ',';
12801280

12811281
if (*p == '[') {
1282-
delim = ']';
1282+
cur_delim = ']';
12831283
p++;
12841284
}
12851285

1286-
ret = ceph_parse_server_name(p, end - p, &addr[i], delim, &ipend);
1286+
ret = ceph_parse_server_name(p, end - p, &addr[i], cur_delim,
1287+
&ipend);
12871288
if (ret)
12881289
goto bad;
12891290
ret = -EINVAL;
12901291

12911292
p = ipend;
12921293

1293-
if (delim == ']') {
1294+
if (cur_delim == ']') {
12941295
if (*p != ']') {
12951296
dout("missing matching ']'\n");
12961297
goto bad;
@@ -1326,11 +1327,11 @@ int ceph_parse_ips(const char *c, const char *end,
13261327
addr[i].type = CEPH_ENTITY_ADDR_TYPE_LEGACY;
13271328
addr[i].nonce = 0;
13281329

1329-
dout("parse_ips got %s\n", ceph_pr_addr(&addr[i]));
1330+
dout("%s got %s\n", __func__, ceph_pr_addr(&addr[i]));
13301331

13311332
if (p == end)
13321333
break;
1333-
if (*p != ',')
1334+
if (*p != delim)
13341335
goto bad;
13351336
p++;
13361337
}

0 commit comments

Comments
 (0)