From: Brice Goglin Date: Thu, 17 Oct 2013 13:10:42 +0000 (+0200) Subject: hwloc-patch: add support for automatically guessing the input topology filename from... X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=5a2ddd83c8e5a0525e0a19e6f4093c05f72de234;p=people%2Fandrewcoop%2Fhwloc.git hwloc-patch: add support for automatically guessing the input topology filename from the XML refname You may do "hwloc-patch refname foo.diff.xml", it will replace "refname" with the topology that was used as a reference when generating the diff. --- diff --git a/utils/hwloc-diff.1in b/utils/hwloc-diff.1in index 8af21c48..20c427d1 100644 --- a/utils/hwloc-diff.1in +++ b/utils/hwloc-diff.1in @@ -33,6 +33,8 @@ Use as the identifier for the reference topology in the output XML difference. It is meant to tell which topology should be used when applying the resulting difference. +hwloc-patch may use that name to automatically load the relevant +reference topology XML. By default, is used without its full path. .TP \fB\-\-version\fR diff --git a/utils/hwloc-patch.1in b/utils/hwloc-patch.1in index 98b68a96..27521060 100644 --- a/utils/hwloc-patch.1in +++ b/utils/hwloc-patch.1in @@ -13,13 +13,13 @@ hwloc-patch \- Apply a topology difference to an existing XML topology .PP .B hwloc-patch [\fIoptions\fR] -\fI\fR +\fI[ | refname]\fR \fI[ | -]\fR \fI\fR .PP .B hwloc-patch [\fIoptions\fR] -\fI\fR +\fI[ | refname]\fR \fI[ | -]\fR . .\" ************************** @@ -44,16 +44,22 @@ hwloc-patch loads the difference between two topologies from a XML file existing topology, generating a new, modified one. . .PP +The XML difference may have been computed earlier with hwloc-diff +or hwloc-compress-dir. +. +.PP If is given, the new, modified topology is stored in that new file. Otherwise, is modified in place. . .PP -If - is used instead of , the topology difference is read from -the standard input. +If \fBrefname\fR is given instead of , the input topology filename +is automatically guessed by reading the refname field of the XML diff file. +By default hwloc-diff generates XML diffs with the right reference topology +filename (without any path prefix). . .PP -The XML difference may have been computed earlier with hwloc-diff -or hwloc-compress-dir. +If \fB-\fR is given instead of , the topology difference is read from +the standard input. . .PP .B NOTE: @@ -73,6 +79,10 @@ Apply a XML topology difference file to an existing topology: $ hwloc-patch fourmi023.xml diff.xml fourmi023-new.xml +Apply a XML topology difference file whole refname field contains the right input topology: + + $ hwloc-patch refname diff.xml fourmi023-new.xml + Apply a XML topology from the standard intput: $ cat diff.xml | hwloc-patch fourmi023.xml - fourmi023-new.xml diff --git a/utils/hwloc-patch.c b/utils/hwloc-patch.c index a829b9f2..52e3a432 100644 --- a/utils/hwloc-patch.c +++ b/utils/hwloc-patch.c @@ -9,13 +9,14 @@ static void usage(const char *callname __hwloc_attribute_unused, FILE *where) { - fprintf(where, "Usage: hwloc-patch [options] [ | - ] []\n"); + fprintf(where, "Usage: hwloc-patch [options] [ | refname] [ | -] []\n"); fprintf(where, "Options:\n"); fprintf(where, " -R --reverse Reverse the sense of the difference\n"); fprintf(where, " --version Report version and exit\n"); } -static int hwloc_diff_read(hwloc_topology_t topo, const char *inputdiff, hwloc_topology_diff_t *firstdiffp) +static int hwloc_diff_read(hwloc_topology_t topo, const char *inputdiff, + hwloc_topology_diff_t *firstdiffp, char **refnamep) { size_t buflen, offset, readlen; char *buffer; @@ -23,7 +24,7 @@ static int hwloc_diff_read(hwloc_topology_t topo, const char *inputdiff, hwloc_t int err; if (strcmp(inputdiff, "-")) - return hwloc_topology_diff_load_xml(topo, inputdiff, firstdiffp, NULL); + return hwloc_topology_diff_load_xml(topo, inputdiff, firstdiffp, refnamep); buflen = 4096; buffer = malloc(buflen+1); /* one more byte for the ending \0 */ @@ -47,7 +48,7 @@ static int hwloc_diff_read(hwloc_topology_t topo, const char *inputdiff, hwloc_t readlen = buflen/2; } - err = hwloc_topology_diff_load_xmlbuffer(topo, buffer, offset+1, firstdiffp, NULL); + err = hwloc_topology_diff_load_xmlbuffer(topo, buffer, offset+1, firstdiffp, refnamep); free(buffer); return err; @@ -63,7 +64,7 @@ int main(int argc, char *argv[]) hwloc_topology_diff_t firstdiff = NULL; unsigned long flags = HWLOC_TOPOLOGY_FLAG_WHOLE_IO | HWLOC_TOPOLOGY_FLAG_ICACHES; unsigned long patchflags = 0; - char *callname, *input, *inputdiff, *output = NULL; + char *callname, *input, *inputdiff, *output = NULL, *refname = NULL; int err; putenv("HWLOC_XML_VERBOSE=1"); @@ -101,21 +102,43 @@ int main(int argc, char *argv[]) argv++; } + /* load a temporary topology so that we can play with diffs */ hwloc_topology_init(&topo); - hwloc_topology_set_flags(topo, flags); - err = hwloc_topology_set_xml(topo, input); - if (err < 0) { - fprintf(stderr, "Failed to load XML topology %s\n", input); - goto out; - } hwloc_topology_load(topo); - err = hwloc_diff_read(topo, inputdiff, &firstdiff); + /* load the diff and get the refname */ + err = hwloc_diff_read(topo, inputdiff, &firstdiff, &refname); if (err < 0) { fprintf(stderr, "Failed to load XML topology diff %s\n", inputdiff); goto out_with_topo; } + /* switch to the actual input topology */ + hwloc_topology_destroy(topo); + hwloc_topology_init(&topo); + hwloc_topology_set_flags(topo, flags); + if (!strcmp(input, "refname")) { + /* use the diff refname as input */ + if (!refname) { + fprintf(stderr, "Couldn't find the reference topology name from the input diff %s\n", inputdiff); + goto out_with_diff; + } + err = hwloc_topology_set_xml(topo, refname); + if (err < 0) { + fprintf(stderr, "Failed to load XML topology %s (from input diff %s refname)\n", refname, inputdiff); + goto out; + } + } else { + /* use the given input */ + err = hwloc_topology_set_xml(topo, input); + if (err < 0) { + fprintf(stderr, "Failed to load XML topology %s\n", input); + goto out; + } + } + + hwloc_topology_load(topo); + err = hwloc_topology_diff_apply(topo, firstdiff, patchflags); if (err < 0) { fprintf(stderr, "Failed to%s apply topology diff %s, failed for hunk #%d hunk\n", diff --git a/utils/test-hwloc-diffpatch.sh.in b/utils/test-hwloc-diffpatch.sh.in index cfd8ddf0..81df16ad 100644 --- a/utils/test-hwloc-diffpatch.sh.in +++ b/utils/test-hwloc-diffpatch.sh.in @@ -32,16 +32,19 @@ fi (umask 077 && mkdir "$tmp") } || exit $? -diffoutput="$tmp/test-hwloc-diffpatch.diff.xml" -output1="$tmp/test-hwloc-diffpatch.output1" -output2="$tmp/test-hwloc-diffpatch.output2" +cd "$tmp" +diffoutput="test-hwloc-diffpatch.diff.xml" +output1="test-hwloc-diffpatch.output1" +output2="test-hwloc-diffpatch.output2" set -e $diff $HWLOC_top_srcdir/utils/test-hwloc-diffpatch.input1 $HWLOC_top_srcdir/utils/test-hwloc-diffpatch.input2 > $diffoutput -cat $diffoutput | $patch $HWLOC_top_srcdir/utils/test-hwloc-diffpatch.input1 - $output1 +cp $HWLOC_top_srcdir/utils/test-hwloc-diffpatch.input1 . +#cat $diffoutput | $patch $HWLOC_top_srcdir/utils/test-hwloc-diffpatch.input1 - $output1 +cat $diffoutput | $patch refname - $output1 $patch -R $HWLOC_top_srcdir/utils/test-hwloc-diffpatch.input2 $diffoutput $output2 -diff @HWLOC_DIFF_U@ $HWLOC_top_srcdir/utils/test-hwloc-diffpatch.input1 "$output2" -diff @HWLOC_DIFF_U@ $HWLOC_top_srcdir/utils/test-hwloc-diffpatch.input2 "$output1" +diff -u $HWLOC_top_srcdir/utils/test-hwloc-diffpatch.input1 "$output2" +diff -u $HWLOC_top_srcdir/utils/test-hwloc-diffpatch.input2 "$output1" rm -rf "$tmp"