~ubuntu-branches/ubuntu/raring/libvirt/raring

« back to all changes in this revision

Viewing changes to src/conf/interface_conf.c

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-11-19 10:41:02 UTC
  • mfrom: (1.2.15) (223.1.2 raring-proposed)
  • Revision ID: package-import@ubuntu.com-20121119104102-l6ewdppikysbzztu
Tags: 1.0.0-0ubuntu2
debian/patches/add-armhf-sysinfo-infomration.patch: Disable
to fix FTBFS on arm.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 * Lesser General Public License for more details.
15
15
 *
16
16
 * You should have received a copy of the GNU Lesser General Public
17
 
 * License along with this library; if not, write to the Free Software
18
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 
17
 * License along with this library.  If not, see
 
18
 * <http://www.gnu.org/licenses/>.
19
19
 *
20
20
 * Author: Daniel Veillard <veillard@redhat.com>
21
21
 *         Laine Stump <laine@redhat.com>
45
45
virInterfaceDefDevFormat(virBufferPtr buf,
46
46
                         const virInterfaceDefPtr def, int level);
47
47
 
48
 
#define virInterfaceReportError(code, ...)                              \
49
 
    virReportErrorHelper(VIR_FROM_INTERFACE, code, __FILE__,            \
50
 
                         __FUNCTION__, __LINE__, __VA_ARGS__)
51
 
 
52
48
static
53
49
void virInterfaceIpDefFree(virInterfaceIpDefPtr def) {
54
50
    if (def == NULL)
122
118
 
123
119
    tmp = virXPathString("string(./@name)", ctxt);
124
120
    if (tmp == NULL) {
125
 
        virInterfaceReportError(VIR_ERR_XML_ERROR,
126
 
                                "%s",  _("interface has no name"));
 
121
        virReportError(VIR_ERR_XML_ERROR,
 
122
                       "%s",  _("interface has no name"));
127
123
        return -1;
128
124
    }
129
125
    def->name = tmp;
138
134
 
139
135
    ret = virXPathULong("string(./mtu/@size)", ctxt, &mtu);
140
136
    if ((ret == -2) || ((ret == 0) && (mtu > 100000))) {
141
 
        virInterfaceReportError(VIR_ERR_XML_ERROR,
142
 
                         "%s", _("interface mtu value is improper"));
 
137
        virReportError(VIR_ERR_XML_ERROR,
 
138
                       "%s", _("interface mtu value is improper"));
143
139
        return -1;
144
140
    } else if (ret == 0) {
145
141
        def->mtu = (unsigned int) mtu;
162
158
    else if (STREQ(tmp, "none"))
163
159
        def->startmode = VIR_INTERFACE_START_NONE;
164
160
    else {
165
 
        virInterfaceReportError(VIR_ERR_XML_ERROR,
166
 
                                _("unknown interface startmode %s"), tmp);
 
161
        virReportError(VIR_ERR_XML_ERROR,
 
162
                       _("unknown interface startmode %s"), tmp);
167
163
        VIR_FREE(tmp);
168
164
        return -1;
169
165
    }
194
190
    else if (STREQ(tmp, "balance-alb"))
195
191
        ret = VIR_INTERFACE_BOND_BALALB;
196
192
    else {
197
 
        virInterfaceReportError(VIR_ERR_XML_ERROR,
198
 
                                _("unknown bonding mode %s"), tmp);
 
193
        virReportError(VIR_ERR_XML_ERROR,
 
194
                       _("unknown bonding mode %s"), tmp);
199
195
        ret = -1;
200
196
    }
201
197
    VIR_FREE(tmp);
215
211
    else if (STREQ(tmp, "netif"))
216
212
        ret = VIR_INTERFACE_BOND_MII_NETIF;
217
213
    else {
218
 
        virInterfaceReportError(VIR_ERR_XML_ERROR,
219
 
                                _("unknown mii bonding carrier %s"), tmp);
 
214
        virReportError(VIR_ERR_XML_ERROR,
 
215
                       _("unknown mii bonding carrier %s"), tmp);
220
216
        ret = -1;
221
217
    }
222
218
    VIR_FREE(tmp);
238
234
    else if (STREQ(tmp, "all"))
239
235
        ret = VIR_INTERFACE_BOND_ARP_ALL;
240
236
    else {
241
 
        virInterfaceReportError(VIR_ERR_XML_ERROR,
242
 
                                _("unknown arp bonding validate %s"), tmp);
 
237
        virReportError(VIR_ERR_XML_ERROR,
 
238
                       _("unknown arp bonding validate %s"), tmp);
243
239
        ret = -1;
244
240
    }
245
241
    VIR_FREE(tmp);
264
260
        else if (STREQ(tmp, "no"))
265
261
            def->peerdns = 0;
266
262
        else {
267
 
            virInterfaceReportError(VIR_ERR_XML_ERROR,
268
 
                              _("unknown dhcp peerdns value %s"), tmp);
 
263
            virReportError(VIR_ERR_XML_ERROR,
 
264
                           _("unknown dhcp peerdns value %s"), tmp);
269
265
            ret = -1;
270
266
        }
271
267
        VIR_FREE(tmp);
290
286
        if (ret == 0)
291
287
            def->prefix = (int) l;
292
288
        else if (ret == -2) {
293
 
            virInterfaceReportError(VIR_ERR_XML_ERROR,
294
 
                              "%s", _("Invalid ip address prefix value"));
 
289
            virReportError(VIR_ERR_XML_ERROR,
 
290
                           "%s", _("Invalid ip address prefix value"));
295
291
            return -1;
296
292
        }
297
293
    }
450
446
        ctxt->node = protoNodes[pp];
451
447
        tmp = virXPathString("string(./@family)", ctxt);
452
448
        if (tmp == NULL) {
453
 
            virInterfaceReportError(VIR_ERR_XML_ERROR,
454
 
                                    "%s", _("protocol misses the family attribute"));
 
449
            virReportError(VIR_ERR_XML_ERROR,
 
450
                           "%s", _("protocol misses the family attribute"));
455
451
            virInterfaceProtocolDefFree(proto);
456
452
            goto error;
457
453
        }
469
465
                goto error;
470
466
            }
471
467
        } else {
472
 
            virInterfaceReportError(VIR_ERR_XML_ERROR,
473
 
                                    _("unsupported protocol family '%s'"), tmp);
 
468
            virReportError(VIR_ERR_XML_ERROR,
 
469
                           _("unsupported protocol family '%s'"), tmp);
474
470
            virInterfaceProtocolDefFree(proto);
475
471
            goto error;
476
472
        }
543
539
    }
544
540
 
545
541
    if (nbItf == 0) {
546
 
        virInterfaceReportError(VIR_ERR_XML_ERROR,
547
 
                                "%s", _("bond has no interfaces"));
 
542
        virReportError(VIR_ERR_XML_ERROR,
 
543
                       "%s", _("bond has no interfaces"));
548
544
        ret = -1;
549
545
        goto error;
550
546
    }
592
588
 
593
589
        ret = virXPathULong("string(./miimon/@freq)", ctxt, &tmp);
594
590
        if ((ret == -2) || (ret == -1)) {
595
 
            virInterfaceReportError(VIR_ERR_XML_ERROR,
596
 
                     "%s", _("bond interface miimon freq missing or invalid"));
 
591
            virReportError(VIR_ERR_XML_ERROR,
 
592
                           "%s", _("bond interface miimon freq missing or invalid"));
597
593
            goto error;
598
594
        }
599
595
        def->data.bond.frequency = (int) tmp;
600
596
 
601
597
        ret = virXPathULong("string(./miimon/@downdelay)", ctxt, &tmp);
602
598
        if (ret == -2) {
603
 
            virInterfaceReportError(VIR_ERR_XML_ERROR,
604
 
                     "%s", _("bond interface miimon downdelay invalid"));
 
599
            virReportError(VIR_ERR_XML_ERROR,
 
600
                           "%s", _("bond interface miimon downdelay invalid"));
605
601
            goto error;
606
602
        } else if (ret == 0) {
607
603
            def->data.bond.downdelay = (int) tmp;
609
605
 
610
606
        ret = virXPathULong("string(./miimon/@updelay)", ctxt, &tmp);
611
607
        if (ret == -2) {
612
 
            virInterfaceReportError(VIR_ERR_XML_ERROR,
613
 
                     "%s", _("bond interface miimon updelay invalid"));
 
608
            virReportError(VIR_ERR_XML_ERROR,
 
609
                           "%s", _("bond interface miimon updelay invalid"));
614
610
            goto error;
615
611
        } else if (ret == 0) {
616
612
            def->data.bond.updelay = (int) tmp;
628
624
 
629
625
        ret = virXPathULong("string(./arpmon/@interval)", ctxt, &tmp);
630
626
        if ((ret == -2) || (ret == -1)) {
631
 
            virInterfaceReportError(VIR_ERR_XML_ERROR,
632
 
                 "%s", _("bond interface arpmon interval missing or invalid"));
 
627
            virReportError(VIR_ERR_XML_ERROR,
 
628
                           "%s", _("bond interface arpmon interval missing or invalid"));
633
629
            goto error;
634
630
        }
635
631
        def->data.bond.interval = (int) tmp;
637
633
        def->data.bond.target =
638
634
            virXPathString("string(./arpmon/@target)", ctxt);
639
635
        if (def->data.bond.target == NULL) {
640
 
            virInterfaceReportError(VIR_ERR_XML_ERROR,
641
 
                 "%s", _("bond interface arpmon target missing"));
 
636
            virReportError(VIR_ERR_XML_ERROR,
 
637
                           "%s", _("bond interface arpmon target missing"));
642
638
            ret = -1;
643
639
            goto error;
644
640
        }
658
654
                         xmlXPathContextPtr ctxt) {
659
655
    def->data.vlan.tag = virXPathString("string(./@tag)", ctxt);
660
656
    if (def->data.vlan.tag == NULL) {
661
 
        virInterfaceReportError(VIR_ERR_XML_ERROR,
662
 
                    "%s", _("vlan interface misses the tag attribute"));
 
657
        virReportError(VIR_ERR_XML_ERROR,
 
658
                       "%s", _("vlan interface misses the tag attribute"));
663
659
        return -1;
664
660
    }
665
661
 
666
662
    def->data.vlan.devname =
667
663
         virXPathString("string(./interface/@name)", ctxt);
668
664
    if (def->data.vlan.devname == NULL) {
669
 
        virInterfaceReportError(VIR_ERR_XML_ERROR,
670
 
                    "%s", _("vlan interface misses name attribute"));
 
665
        virReportError(VIR_ERR_XML_ERROR,
 
666
                       "%s", _("vlan interface misses name attribute"));
671
667
        return -1;
672
668
    }
673
669
    return 0;
683
679
    /* check @type */
684
680
    tmp = virXPathString("string(./@type)", ctxt);
685
681
    if (tmp == NULL) {
686
 
        virInterfaceReportError(VIR_ERR_XML_ERROR,
687
 
                                "%s", _("interface misses the type attribute"));
 
682
        virReportError(VIR_ERR_XML_ERROR,
 
683
                       "%s", _("interface misses the type attribute"));
688
684
        return NULL;
689
685
    }
690
686
    type = virInterfaceTypeFromString(tmp);
691
687
    if (type == -1) {
692
 
        virInterfaceReportError(VIR_ERR_XML_ERROR,
693
 
                                _("unknown interface type %s"), tmp);
 
688
        virReportError(VIR_ERR_XML_ERROR,
 
689
                       _("unknown interface type %s"), tmp);
694
690
        VIR_FREE(tmp);
695
691
        return NULL;
696
692
    }
710
706
        || (parentIfType == VIR_INTERFACE_TYPE_ETHERNET)
711
707
        || (parentIfType == VIR_INTERFACE_TYPE_VLAN))
712
708
        {
713
 
        virInterfaceReportError(VIR_ERR_XML_ERROR,
714
 
                                _("interface has unsupported type '%s'"),
715
 
                                virInterfaceTypeToString(type));
 
709
        virReportError(VIR_ERR_XML_ERROR,
 
710
                       _("interface has unsupported type '%s'"),
 
711
                       virInterfaceTypeToString(type));
716
712
        goto error;
717
713
    }
718
714
    def->type = type;
747
743
 
748
744
            bridge = virXPathNode("./bridge[1]", ctxt);
749
745
            if (bridge == NULL) {
750
 
                virInterfaceReportError(VIR_ERR_XML_ERROR,
751
 
                                        "%s", _("bridge interface misses the bridge element"));
 
746
                virReportError(VIR_ERR_XML_ERROR,
 
747
                               "%s", _("bridge interface misses the bridge element"));
752
748
                goto error;
753
749
            }
754
750
            tmp = virXMLPropString(bridge, "stp");
759
755
                } else if (STREQ(tmp, "off")) {
760
756
                    def->data.bridge.stp = 0;
761
757
                } else {
762
 
                    virInterfaceReportError(VIR_ERR_XML_ERROR,
763
 
                          _("bridge interface stp should be on or off got %s"),
764
 
                                            tmp);
 
758
                    virReportError(VIR_ERR_XML_ERROR,
 
759
                                   _("bridge interface stp should be on or off got %s"),
 
760
                                   tmp);
765
761
                    VIR_FREE(tmp);
766
762
                    goto error;
767
763
                }
790
786
 
791
787
            bond = virXPathNode("./bond[1]", ctxt);
792
788
            if (bond == NULL) {
793
 
                virInterfaceReportError(VIR_ERR_XML_ERROR,
794
 
                            "%s", _("bond interface misses the bond element"));
 
789
                virReportError(VIR_ERR_XML_ERROR,
 
790
                               "%s", _("bond interface misses the bond element"));
795
791
                goto error;
796
792
            }
797
793
            ctxt->node = bond;
811
807
                goto error;
812
808
            vlan = virXPathNode("./vlan[1]", ctxt);
813
809
            if (vlan == NULL) {
814
 
                virInterfaceReportError(VIR_ERR_XML_ERROR,
815
 
                            "%s", _("vlan interface misses the vlan element"));
 
810
                virReportError(VIR_ERR_XML_ERROR,
 
811
                               "%s", _("vlan interface misses the vlan element"));
816
812
                goto error;
817
813
            }
818
814
            ctxt->node = vlan;
839
835
    virInterfaceDefPtr def = NULL;
840
836
 
841
837
    if (!xmlStrEqual(root->name, BAD_CAST "interface")) {
842
 
        virInterfaceReportError(VIR_ERR_XML_ERROR,
843
 
                                _("unexpected root element <%s>, "
844
 
                                  "expecting <interface>"),
845
 
                                root->name);
 
838
        virReportError(VIR_ERR_XML_ERROR,
 
839
                       _("unexpected root element <%s>, "
 
840
                         "expecting <interface>"),
 
841
                       root->name);
846
842
        return NULL;
847
843
    }
848
844
 
947
943
        virBufferAddLit(buf, "/>\n");
948
944
    } else if (def->data.bond.monit == VIR_INTERFACE_BOND_MONIT_ARP) {
949
945
        if (def->data.bond.target == NULL) {
950
 
            virInterfaceReportError(VIR_ERR_INTERNAL_ERROR,
951
 
                          "%s", _("bond arp monitoring has no target"));
 
946
            virReportError(VIR_ERR_INTERNAL_ERROR,
 
947
                           "%s", _("bond arp monitoring has no target"));
952
948
            return -1;
953
949
        }
954
950
        virBufferAsprintf(buf, "%*s    <arpmon interval='%d' target='%s'",
975
971
virInterfaceVlanDefFormat(virBufferPtr buf,
976
972
                          const virInterfaceDefPtr def, int level) {
977
973
    if (def->data.vlan.tag == NULL) {
978
 
        virInterfaceReportError(VIR_ERR_INTERNAL_ERROR,
979
 
                                "%s", _("vlan misses the tag name"));
 
974
        virReportError(VIR_ERR_INTERNAL_ERROR,
 
975
                       "%s", _("vlan misses the tag name"));
980
976
        return -1;
981
977
    }
982
978
 
1057
1053
            mode = "hotplug";
1058
1054
            break;
1059
1055
        default:
1060
 
            virInterfaceReportError(VIR_ERR_INTERNAL_ERROR,
1061
 
                        "%s", _("virInterfaceDefFormat unknown startmode"));
 
1056
            virReportError(VIR_ERR_INTERNAL_ERROR,
 
1057
                           "%s", _("virInterfaceDefFormat unknown startmode"));
1062
1058
            return -1;
1063
1059
    }
1064
1060
    virBufferAsprintf(buf, "%*s  <start mode='%s'/>\n", level*2, "", mode);
1071
1067
    const char *type = NULL;
1072
1068
 
1073
1069
    if (def == NULL) {
1074
 
        virInterfaceReportError(VIR_ERR_INTERNAL_ERROR,
1075
 
                        "%s", _("virInterfaceDefFormat NULL def"));
 
1070
        virReportError(VIR_ERR_INTERNAL_ERROR,
 
1071
                       "%s", _("virInterfaceDefFormat NULL def"));
1076
1072
        goto cleanup;
1077
1073
    }
1078
1074
 
1079
1075
    if ((def->name == NULL) && (def->type != VIR_INTERFACE_TYPE_VLAN)) {
1080
 
        virInterfaceReportError(VIR_ERR_INTERNAL_ERROR,
1081
 
                        "%s", _("virInterfaceDefFormat missing interface name"));
 
1076
        virReportError(VIR_ERR_INTERNAL_ERROR,
 
1077
                       "%s", _("virInterfaceDefFormat missing interface name"));
1082
1078
        goto cleanup;
1083
1079
    }
1084
1080
 
1085
1081
    if (!(type = virInterfaceTypeToString(def->type))) {
1086
 
        virInterfaceReportError(VIR_ERR_INTERNAL_ERROR,
1087
 
                        _("unexpected interface type %d"), def->type);
 
1082
        virReportError(VIR_ERR_INTERNAL_ERROR,
 
1083
                       _("unexpected interface type %d"), def->type);
1088
1084
        goto cleanup;
1089
1085
    }
1090
1086
 
1285
1281
        return NULL;
1286
1282
    }
1287
1283
    if (virMutexInit(&iface->lock) < 0) {
1288
 
        virInterfaceReportError(VIR_ERR_INTERNAL_ERROR,
1289
 
                                "%s", _("cannot initialize mutex"));
 
1284
        virReportError(VIR_ERR_INTERNAL_ERROR,
 
1285
                       "%s", _("cannot initialize mutex"));
1290
1286
        VIR_FREE(iface);
1291
1287
        return NULL;
1292
1288
    }