]> xenbits.xensource.com Git - people/andrewcoop/hwloc.git/commitdiff
hwloc-patch: add support for automatically guessing the input topology filename from...
authorBrice Goglin <Brice.Goglin@inria.fr>
Thu, 17 Oct 2013 13:10:42 +0000 (15:10 +0200)
committerBrice Goglin <Brice.Goglin@inria.fr>
Thu, 17 Oct 2013 14:34:21 +0000 (16:34 +0200)
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.

utils/hwloc-diff.1in
utils/hwloc-patch.1in
utils/hwloc-patch.c
utils/test-hwloc-diffpatch.sh.in

index 8af21c481bdaab41873de1c07fba5372f1825015..20c427d120c9d7e32f9bdf0b6036582919f653c7 100644 (file)
@@ -33,6 +33,8 @@ Use <name> 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, <input1.xml> is used without its full path.
 .TP
 \fB\-\-version\fR
index 98b68a9623422f85d3a4bf1aa82a5999388cbe01..27521060aa5949d562b0ae45e85c7360e363d989 100644 (file)
@@ -13,13 +13,13 @@ hwloc-patch \- Apply a topology difference to an existing XML topology
 .PP
 .B hwloc-patch
 [\fIoptions\fR]
-\fI<topology.xml>\fR
+\fI[<topology.xml> | refname]\fR
 \fI[<diff.xml> | -]\fR
 \fI<output.xml>\fR
 .PP
 .B hwloc-patch
 [\fIoptions\fR]
-\fI<topology.xml>\fR
+\fI[<topology.xml> | refname]\fR
 \fI[<diff.xml> | -]\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 <output.xml> is given, the new, modified topology is stored in that
 new file. Otherwise, <topology.xml> is modified in place.
 .
 .PP
-If - is used instead of <diff.xml>, the topology difference is read from
-the standard input.
+If \fBrefname\fR is given instead of <topology.xml>, 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 <diff.xml>, 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
index a829b9f2e4040154eb5cb7a711463644ccffa9ec..52e3a4321b23f33b84a207db5057a1320065203f 100644 (file)
@@ -9,13 +9,14 @@
 
 static void usage(const char *callname __hwloc_attribute_unused, FILE *where)
 {
-       fprintf(where, "Usage: hwloc-patch [options] <old.xml> [ <diff.xml> | - ] [<output.xml>]\n");
+       fprintf(where, "Usage: hwloc-patch [options] [<old.xml> | refname] [<diff.xml> | -] [<output.xml>]\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",
index cfd8ddf01c165e6bd9bfa7c55d89bbf2264f346a..81df16ad794d320943b1e8fda7db15124193523d 100644 (file)
@@ -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"