Skip to content

Commit bc95f55

Browse files
committed
tree: remove nvme_update_config
nvme_update_config is used to dump the current configuration to the either stdout or a config file. There is also nvme_dump_config which does almost the same thing. The only difference is that nvme_update_config is testing if the something has been modified. The modified tracking happens on a global level and almost all operations on the tree will set the modified flag. This is actually not really needed. nvme-cli uses for the 'config' command which expects that the config is updated. One could argue that the config should not be written when nothing changes. But this could be done in a different way, e.g. create a temp config and compare it to the original and only overwrite the original if something changes. But no one complained that the config is overwritten all the time so far (remember the modified flag is almost certainly always set). Signed-off-by: Daniel Wagner <[email protected]>
1 parent 2f060eb commit bc95f55

8 files changed

Lines changed: 13 additions & 38 deletions

File tree

fabrics.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ int fabrics_discovery(const char *desc, int argc, char **argv, bool connect)
579579

580580
out_free:
581581
if (dump_config)
582-
nvme_dump_config(ctx);
582+
nvme_dump_config(ctx, NULL);
583583

584584
return ret;
585585
}
@@ -714,7 +714,7 @@ int fabrics_connect(const char *desc, int argc, char **argv)
714714
}
715715

716716
if (dump_config)
717-
nvme_dump_config(ctx);
717+
nvme_dump_config(ctx, NULL);
718718

719719
return 0;
720720
}
@@ -1029,10 +1029,10 @@ int fabrics_config(const char *desc, int argc, char **argv)
10291029
}
10301030

10311031
if (update_config)
1032-
nvme_update_config(ctx);
1032+
nvme_dump_config(ctx, config_file);
10331033

10341034
if (dump_config)
1035-
nvme_dump_config(ctx);
1035+
nvme_dump_config(ctx, NULL);
10361036

10371037
return 0;
10381038
}

libnvme/libnvme/nvme.i

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,11 +528,8 @@ struct nvme_ns {
528528
void refresh_topology() {
529529
nvme_refresh_topology($self);
530530
}
531-
void update_config() {
532-
nvme_update_config($self);
533-
}
534531
void dump_config() {
535-
nvme_dump_config($self);
532+
nvme_dump_config($self, NULL);
536533
}
537534
}
538535

libnvme/src/libnvme.ld

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ LIBNVME_2_0 {
275275
nvme_transport_handle_set_submit_entry;
276276
nvme_transport_handle_set_submit_exit;
277277
nvme_unlink_ctrl;
278-
nvme_update_config;
279278
nvme_update_key;
280279
nvme_uuid_find;
281280
nvme_uuid_from_string;

libnvme/src/nvme/private.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,6 @@ struct nvme_global_ctx {
267267
struct list_head endpoints; /* MI endpoints */
268268
struct list_head hosts;
269269
struct nvme_log log;
270-
bool modified;
271270
bool mi_probe_enabled;
272271
bool create_only;
273272
bool dry_run;

libnvme/src/nvme/tree.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -404,17 +404,9 @@ int nvme_scan(const char *config_file, struct nvme_global_ctx **ctxp)
404404
return ret;
405405
}
406406

407-
int nvme_update_config(struct nvme_global_ctx *ctx)
407+
int nvme_dump_config(struct nvme_global_ctx *ctx, const char *config_file)
408408
{
409-
if (!ctx->modified || !ctx->config_file)
410-
return 0;
411-
412-
return json_update_config(ctx, ctx->config_file);
413-
}
414-
415-
int nvme_dump_config(struct nvme_global_ctx *ctx)
416-
{
417-
return json_update_config(ctx, NULL);
409+
return json_update_config(ctx, config_file);
418410
}
419411

420412
int nvme_dump_tree(struct nvme_global_ctx *ctx)
@@ -717,7 +709,6 @@ struct nvme_subsystem *nvme_alloc_subsystem(struct nvme_host *h,
717709
list_head_init(&s->namespaces);
718710
list_node_init(&s->entry);
719711
list_add_tail(&h->subsystems, &s->entry);
720-
h->ctx->modified = true;
721712
return s;
722713
}
723714

@@ -756,7 +747,6 @@ static void __nvme_free_host(struct nvme_host *h)
756747
free(h->hostid);
757748
free(h->dhchap_key);
758749
nvme_host_set_hostsymname(h, NULL);
759-
h->ctx->modified = true;
760750
free(h);
761751
}
762752

@@ -799,7 +789,6 @@ struct nvme_host *nvme_lookup_host(struct nvme_global_ctx *ctx, const char *host
799789
list_node_init(&h->entry);
800790
h->ctx = ctx;
801791
list_add_tail(&ctx->hosts, &h->entry);
802-
ctx->modified = true;
803792

804793
return h;
805794
}
@@ -1870,7 +1859,6 @@ nvme_ctrl_t nvme_lookup_ctrl(nvme_subsystem_t s, const char *transport,
18701859

18711860
c->s = s;
18721861
list_add_tail(&s->ctrls, &c->entry);
1873-
s->h->ctx->modified = true;
18741862

18751863
return c;
18761864
}

libnvme/src/nvme/tree.h

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,26 +1453,18 @@ int nvme_read_config(struct nvme_global_ctx *ctx, const char *config_file);
14531453
*/
14541454
void nvme_refresh_topology(struct nvme_global_ctx *ctx);
14551455

1456-
/**
1457-
* nvme_update_config() - Update JSON configuration
1458-
* @ctx: &struct nvme_global_ctx object
1459-
*
1460-
* Updates the JSON configuration file with the contents of @r.
1461-
*
1462-
* Return: 0 on success, -1 on failure.
1463-
*/
1464-
int nvme_update_config(struct nvme_global_ctx *ctx);
1465-
14661456
/**
14671457
* nvme_dump_config() - Print the JSON configuration
14681458
* @ctx: &struct nvme_global_ctx object
1459+
* @config_file: JSON configuration file.
14691460
*
14701461
* Prints the current contents of the JSON configuration
1471-
* file to stdout.
1462+
* file to the config_file. If connfig_file is not provided it prints
1463+
* to stdout.
14721464
*
14731465
* Return: 0 on success, or negative error code otherwise.
14741466
*/
1475-
int nvme_dump_config(struct nvme_global_ctx *ctx);
1467+
int nvme_dump_config(struct nvme_global_ctx *ctx, const char *config_file);
14761468

14771469
/**
14781470
* nvme_dump_tree() - Dump internal object tree

libnvme/test/config/config-dump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static bool config_dump(const char *file)
2929
if (err)
3030
goto out;
3131

32-
err = nvme_dump_config(ctx);
32+
err = nvme_dump_config(ctx, NULL);
3333
if (err)
3434
goto out;
3535

libnvme/test/config/psk-json.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static bool psk_json_test(char *file)
6969
if (!import_export_key(c))
7070
goto out;
7171

72-
err = nvme_dump_config(ctx);
72+
err = nvme_dump_config(ctx, NULL);
7373
if (err)
7474
goto out;
7575

0 commit comments

Comments
 (0)