~ubuntu-branches/ubuntu/precise/libvirt/precise

« back to all changes in this revision

Viewing changes to src/conf/domain_conf.c

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2012-01-12 23:47:09 UTC
  • Revision ID: package-import@ubuntu.com-20120112234709-1737nvgy6hx19scv
debian/patches/ubuntu/conf-dont-drop-console-def-ondomain-restart.patch:
cherrypicked from upstream to fix 'virsh console'.  (LP: #915355)

Show diffs side-by-side

added added

removed removed

Lines of Context:
965
965
    VIR_FREE(def);
966
966
}
967
967
 
 
968
/* virDomainChrSourceDefIsEqual:
 
969
 * @src: Source
 
970
 * @tgt: Target
 
971
 *
 
972
 * Compares source and target if they contain
 
973
 * the same information.
 
974
 */
 
975
static bool
 
976
virDomainChrSourceDefIsEqual(const virDomainChrSourceDef *src,
 
977
                             const virDomainChrSourceDef *tgt)
 
978
{
 
979
    if (tgt->type != src->type)
 
980
        return false;
 
981
 
 
982
    switch (src->type) {
 
983
    case VIR_DOMAIN_CHR_TYPE_PTY:
 
984
    case VIR_DOMAIN_CHR_TYPE_DEV:
 
985
    case VIR_DOMAIN_CHR_TYPE_FILE:
 
986
    case VIR_DOMAIN_CHR_TYPE_PIPE:
 
987
        return STREQ_NULLABLE(src->data.file.path, tgt->data.file.path);
 
988
        break;
 
989
    case VIR_DOMAIN_CHR_TYPE_UDP:
 
990
        return STREQ_NULLABLE(src->data.udp.bindHost, tgt->data.udp.bindHost) &&
 
991
            STREQ_NULLABLE(src->data.udp.bindService, tgt->data.udp.bindService) &&
 
992
            STREQ_NULLABLE(src->data.udp.connectHost, tgt->data.udp.connectHost) &&
 
993
            STREQ_NULLABLE(src->data.udp.connectService, tgt->data.udp.connectService);
 
994
        break;
 
995
    case VIR_DOMAIN_CHR_TYPE_TCP:
 
996
        return src->data.tcp.listen == tgt->data.tcp.listen &&
 
997
            src->data.tcp.protocol == tgt->data.tcp.protocol &&
 
998
            STREQ_NULLABLE(src->data.tcp.host, tgt->data.tcp.host) &&
 
999
            STREQ_NULLABLE(src->data.tcp.service, tgt->data.tcp.service);
 
1000
        break;
 
1001
    case VIR_DOMAIN_CHR_TYPE_UNIX:
 
1002
        return src->data.nix.listen == tgt->data.nix.listen &&
 
1003
            STREQ_NULLABLE(src->data.nix.path, tgt->data.nix.path);
 
1004
        break;
 
1005
 
 
1006
    case VIR_DOMAIN_CHR_TYPE_VC:
 
1007
    case VIR_DOMAIN_CHR_TYPE_STDIO:
 
1008
    case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
 
1009
        /* nada */
 
1010
        return true;
 
1011
    }
 
1012
 
 
1013
    /* This should happen only on new,
 
1014
     * yet unhandled type */
 
1015
 
 
1016
    return false;
 
1017
}
 
1018
 
968
1019
void virDomainChrDefFree(virDomainChrDefPtr def)
969
1020
{
970
1021
    if (!def)
7235
7286
        goto no_memory;
7236
7287
 
7237
7288
    for (i = 0 ; i < n ; i++) {
 
7289
        bool create_stub = true;
7238
7290
        virDomainChrDefPtr chr = virDomainChrDefParseXML(caps,
7239
7291
                                                         def,
7240
7292
                                                         nodes[i],
7252
7304
         * So if we see that this console device should
7253
7305
         * be a serial device, then we move the config
7254
7306
         * over to def->serials[0] (or discard it if
7255
 
         * that already exists
 
7307
         * that already exists). However, given console
 
7308
         * can already be filled with aliased data of
 
7309
         * def->serials[0]. Keep it then.
7256
7310
         *
7257
7311
         * We then fill def->consoles[0] with a stub
7258
7312
         * just so we get sequencing correct for consoles
7268
7322
 
7269
7323
            /* Either discard or move this chr to the serial config */
7270
7324
            if (def->nserials != 0) {
7271
 
                virDomainChrDefFree(chr);
 
7325
                if (virDomainChrSourceDefIsEqual(&def->serials[0]->source,
 
7326
                                                 &chr->source)) {
 
7327
                    /* Alias to def->serial[0]. Skip it */
 
7328
                    create_stub = false;
 
7329
                } else {
 
7330
                    virDomainChrDefFree(chr);
 
7331
                }
7272
7332
            } else {
7273
7333
                if (VIR_ALLOC_N(def->serials, 1) < 0) {
7274
7334
                    virDomainChrDefFree(chr);
7280
7340
                chr->target.port = 0;
7281
7341
            }
7282
7342
 
7283
 
            /* And create a stub placeholder */
7284
 
            if (VIR_ALLOC(chr) < 0)
7285
 
                goto no_memory;
7286
 
            chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE;
7287
 
            chr->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
 
7343
            if (create_stub) {
 
7344
                /* And create a stub placeholder */
 
7345
                if (VIR_ALLOC(chr) < 0)
 
7346
                    goto no_memory;
 
7347
                chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE;
 
7348
                chr->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL;
 
7349
            }
7288
7350
        }
7289
7351
 
7290
7352
        chr->target.port = i;