Skip to content

Commit 8450aed

Browse files
WescoeurMarkSymsCtx
authored andcommitted
Add an option to never resolve parent path when vhd-util query is called
Signed-off-by: Ronan Abhamon <[email protected]>
1 parent c6ef4d2 commit 8450aed

File tree

3 files changed

+41
-17
lines changed

3 files changed

+41
-17
lines changed

Diff for: include/libvhd.h

+1
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ int vhd_initialize_header_parent_name(vhd_context_t *, const char *);
341341
int vhd_write_parent_locators(vhd_context_t *, const char *);
342342
int vhd_parent_locator_count(vhd_context_t *);
343343
int vhd_parent_locator_get(vhd_context_t *, char **);
344+
int vhd_parent_locator_unresolved_get(vhd_context_t *, char **);
344345
int vhd_custom_parent_set(vhd_context_t *vhd, const char *parent);
345346

346347
int vhd_parent_locator_read(vhd_context_t *, vhd_parent_locator_t *, char **);

Diff for: vhd/lib/libvhd.c

+19-2
Original file line numberDiff line numberDiff line change
@@ -1782,8 +1782,8 @@ vhd_parent_locator_read(vhd_context_t *ctx,
17821782
return err;
17831783
}
17841784

1785-
int
1786-
vhd_parent_locator_get(vhd_context_t *ctx, char **parent)
1785+
static int
1786+
vhd_parent_locator_get_impl(vhd_context_t *ctx, char **parent, bool resolve_parent)
17871787
{
17881788
int i, n, err;
17891789
char *name, *location;
@@ -1807,6 +1807,11 @@ vhd_parent_locator_get(vhd_context_t *ctx, char **parent)
18071807
if (_err)
18081808
continue;
18091809

1810+
if (!resolve_parent) {
1811+
*parent = name;
1812+
return 0;
1813+
}
1814+
18101815
err = vhd_find_parent(ctx, name, &location);
18111816
if (err)
18121817
VHDLOG("%s: couldn't find parent %s (%d)\n",
@@ -1822,6 +1827,18 @@ vhd_parent_locator_get(vhd_context_t *ctx, char **parent)
18221827
return err;
18231828
}
18241829

1830+
int
1831+
vhd_parent_locator_get(vhd_context_t *ctx, char **parent)
1832+
{
1833+
return vhd_parent_locator_get_impl(ctx, parent, true);
1834+
}
1835+
1836+
int
1837+
vhd_parent_locator_unresolved_get(vhd_context_t *ctx, char **parent)
1838+
{
1839+
return vhd_parent_locator_get_impl(ctx, parent, false);
1840+
}
1841+
18251842
/**
18261843
* Overrides the parent with the supplied one.
18271844
*

Diff for: vhd/lib/vhd-util-query.c

+21-15
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,26 @@ vhd_util_query(int argc, char **argv)
4646
char *name;
4747
vhd_context_t vhd;
4848
off64_t currsize;
49-
int ret, err, c, size, physize, parent, fields, depth, fastresize, marker, allocated;
50-
51-
name = NULL;
52-
size = 0;
53-
physize = 0;
54-
parent = 0;
55-
fields = 0;
56-
depth = 0;
57-
fastresize = 0;
58-
marker = 0;
59-
allocated = 0;
60-
49+
int ret, err, c, size, physize, parent, fields, depth, fastresize, marker, allocated, resolve_parent;
50+
51+
name = NULL;
52+
size = 0;
53+
physize = 0;
54+
parent = 0;
55+
fields = 0;
56+
depth = 0;
57+
fastresize = 0;
58+
marker = 0;
59+
allocated = 0;
60+
resolve_parent = 1;
61+
6162
if (!argc || !argv) {
6263
err = -EINVAL;
6364
goto usage;
6465
}
6566

6667
optind = 0;
67-
while ((c = getopt(argc, argv, "n:vspfdSmah")) != -1) {
68+
while ((c = getopt(argc, argv, "n:vspfdSmauh")) != -1) {
6869
switch (c) {
6970
case 'n':
7071
name = optarg;
@@ -93,6 +94,9 @@ vhd_util_query(int argc, char **argv)
9394
case 'a':
9495
allocated = 1;
9596
break;
97+
case 'u':
98+
resolve_parent = 0;
99+
break;
96100
case 'h':
97101
err = 0;
98102
goto usage;
@@ -132,7 +136,7 @@ vhd_util_query(int argc, char **argv)
132136
else {
133137
char *pname;
134138

135-
ret = vhd_parent_locator_get(&vhd, &pname);
139+
ret = resolve_parent ? vhd_parent_locator_get(&vhd, &pname) : vhd_parent_locator_unresolved_get(&vhd, &pname);
136140
if (ret)
137141
printf("query failed\n");
138142
else {
@@ -212,6 +216,8 @@ vhd_util_query(int argc, char **argv)
212216
"[-s print physical utilization (bytes)] [-p print parent] "
213217
"[-f print fields] [-m print marker] [-d print chain depth] "
214218
"[-S print max virtual size (MB) for fast resize] "
215-
"[-a print allocated block count] [-h help]\n");
219+
"[-a print allocated block count] "
220+
"[-u don't resolve parent path] "
221+
"[-h help]\n");
216222
return err;
217223
}

0 commit comments

Comments
 (0)