opennebula-4.90.5-runasuser.diff

Updated patch for OpenNebula 5.0 beta (untested) - Roy Keene, 06/15/2016 07:47 PM

Download (9.58 KB)

View differences:

opennebula-4.90.5-runasuser/src/mad/sh/scripts_common.sh 2016-06-07 11:19:42.476878849 -0500
328 328
    if [ "$FSTYPE" = "swap" ]; then
329 329
        echo "$MKSWAP -L swap $DST"
330 330
    fi
331

  
332
    echo "test -e '${DST}' && chmod 600 '${DST}'"
331 333
}
332 334

  
333 335
#This function executes $2 at $1 host and report error $3
opennebula-4.90.5-runasuser/src/tm/TransferManager.cc 2016-06-06 10:59:32.666520643 -0500
474 474
            << vm->get_hostname() << ":"
475 475
            << vm->get_system_dir() << "/disk." << disk_id << " "
476 476
            << vm->get_oid() << " "
477
            << vm->get_ds_id()
477
            << vm->get_ds_id() << " "
478
            << (vm->get_oid() + 131072) << " "
479
            << (vm->get_oid() + 131072)
478 480
            << endl;
479 481
    }
480 482
    else if ( type == "FS" )
......
505 507
            << vm->get_hostname() << ":"
506 508
            << vm->get_system_dir() << "/disk." << disk_id << " "
507 509
            << vm->get_oid() << " "
508
            << vm->get_ds_id()
510
            << vm->get_ds_id() << " "
511
            << (vm->get_oid() + 131072) << " "
512
            << (vm->get_oid() + 131072)
509 513
            << endl;
510 514
    }
511 515
    else
......
556 560
        xfr << vm->get_hostname() << ":"
557 561
            << vm->get_system_dir() << "/disk." << disk_id << " "
558 562
            << vm->get_oid() << " "
559
            << ds_id
563
            << ds_id << " "
564
            << (vm->get_oid() + 131072) << " "
565
            << (vm->get_oid() + 131072)
560 566
            << endl;
561 567
    }
562 568

  
......
613 619
        << vm->get_hostname() << ":"
614 620
        << base_dst.str() << " "
615 621
        << vm->get_oid() << " "
616
        << ds_id
622
        << ds_id << " "
623
        << (vm->get_oid() + 131072) << " "
624
        << (vm->get_oid() + 131072)
617 625
        << endl;
618 626

  
619 627
    return base_dst.str();
opennebula-4.90.5-runasuser/src/tm_mad/common/mkimage 2016-06-07 11:21:50.033878647 -0500
31 31
VMID=$4
32 32
DSID=$5
33 33

  
34
VMUID="$6"
35
VMGID="$7"
36

  
34 37
if [ -z "${ONE_LOCATION}" ]; then
35 38
    TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
39
    KVMRC=/var/lib/one/remotes/vmm/kvm/kvmrc
36 40
else
37 41
    TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh
42
    KVMRC=$ONE_LOCATION/var/remotes/vmm/kvm/kvmrc
38 43
fi
39 44

  
40 45
. $TMCOMMON
46
. $KVMRC
41 47

  
42 48
#-------------------------------------------------------------------------------
43 49
# Set dst path and dir
......
57 63
set -e
58 64
export PATH=/usr/sbin:/sbin:\$PATH
59 65
$MKFS_CMD
66
VMUID="${VMUID}"
67
VMGID="${VMGID}"
68
if [ -z "\${VMUID}" -o -z "\${VMGID}" ]; then
69
    eval "\$(virsh -c $LIBVIRT_URI dumpxml one-$VMID | grep '<label>+.*:+.*</label>' | sed 's@.*<label>\(.*\)</label>@\1@;s@^+@VMUID=@;s@:+@; VMGID=@')"
70
fi
71
if [ -n "\${VMUID}" -a -n "\${VMGID}" ]; then
72
  sudo chown "\${VMUID}:\${VMGID}" $DST_PATH
73
fi
60 74
EOF
61 75
)
62 76

  
opennebula-4.90.5-runasuser/src/tm_mad/common/mkswap 2016-06-07 11:23:06.406878526 -0500
29 29
VMID=$3
30 30
DSID=$4
31 31

  
32
`dirname $0`/mkimage $SIZE swap $DST $VMID $DSID
32
VMUID="$5"
33
VMGID="$6"
34

  
35
`dirname $0`/mkimage $SIZE swap $DST $VMID $DSID $VMUID $VMGID
opennebula-4.90.5-runasuser/src/tm_mad/qcow2/clone 2016-06-07 11:32:14.897877659 -0500
30 30
VMID=$3
31 31
DSID=$4
32 32

  
33
VMUID="$5"
34
VMGID="$6"
35

  
33 36
if [ -z "${ONE_LOCATION}" ]; then
34 37
    TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
35 38
else
......
92 95
#-------------------------------------------------------------------------------
93 96
# Clone (cp) SRC into DST
94 97
#-------------------------------------------------------------------------------
98
if [ -n "${VMUID}" -a -n "${VMGID}" ]; then
99
    ADD_CMD=" && sudo chmod 600 $DST_PATH && sudo chown ${VMUID}:${VMGID} $DST_PATH"
100
fi
95 101

  
96 102
type="$(file -b --mime-type $SRC_PATH)"
97 103

  
98 104
if [ "$type" == "application/x-iso9660-image" ]; then
99
    CLONE_CMD="cp ${SRC_PATH} ${DST_PATH}"
105
    CLONE_CMD="cp ${SRC_PATH} ${DST_PATH}${ADD_CMD}"
100 106
else
101 107
    if [ -n "$ORIGINAL_SIZE" -a "$SIZE" -gt "$ORIGINAL_SIZE" ]; then
102 108
       RESIZE_CMD="qemu-img resize ${DST_PATH} ${SIZE}M"
......
106 112
cd $DST_DIR
107 113
mkdir -p ${DST_PATH}.snap
108 114
rm -f $DST_PATH
109
$QEMU_IMG create -b $SRC_PATH -f qcow2 $QCOW2_OPTIONS ${DST_PATH}.snap/0
115
$QEMU_IMG create -b $SRC_PATH -f qcow2 $QCOW2_OPTIONS ${DST_PATH}.snap/0${ADD_CMD}
110 116
ln -s ${DST_FILE}.snap/0 ${DST_PATH}
111 117
cd ${DST_PATH}.snap
112 118
ln -s . ${DST_PATH}.snap/${DST_FILE}.snap
opennebula-4.90.5-runasuser/src/tm_mad/shared/clone 2016-06-07 11:34:55.542877405 -0500
30 30
VMID=$3
31 31
DSID=$4
32 32

  
33
VMUID=$5
34
VMGID=$6
35

  
33 36
if [ -z "${ONE_LOCATION}" ]; then
34 37
    TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh
35 38
else
......
91 94
# Clone (cp) SRC into DST
92 95
#-------------------------------------------------------------------------------
93 96

  
97
if [ -n "${VMUID}" -a -n "${VMGID}" ]; then
98
	ADD_CMD="&& sudo chmod 600 ${DST_PATH} && sudo chown ${VMUID}:${VMGID} ${DST_PATH}"
99
fi
100

  
94 101
if [ -n "$ORIGINAL_SIZE" -a "$SIZE" -gt "$ORIGINAL_SIZE" ]; then
95 102
   RESIZE_CMD="; qemu-img resize ${DST_PATH} ${SIZE}M"
96 103
fi
......
99 106

  
100 107
CLONE_CMD="cd ${DST_DIR}; \
101 108
    cp ${SRC_PATH} ${DST_PATH} \
102
    ${RESIZE_CMD}"
109
    ${RESIZE_CMD}${ADD_CMD}"
103 110

  
104 111
ssh_exec_and_log $DST_HOST \
105 112
                 "$CLONE_CMD" \
opennebula-4.90.5-runasuser/src/tm_mad/shared/ln 2016-06-06 10:59:32.667520643 -0500
89 89
log "Linking $SRC_PATH in $DST"
90 90

  
91 91
ssh_exec_and_log $DST_HOST \
92
                "cd $DST_DIR; rm -f $DST_PATH ; ln -s $SRC_PATH $DST_PATH" \
92
                "cd $DST_DIR && rm -f $DST_PATH && ln -s $SRC_PATH $DST_PATH" \
93 93
                "Error linking $SRC to $DST"
94 94

  
95 95
exit 0
opennebula-4.90.5-runasuser/src/tm_mad/ssh/mv 2016-06-06 10:59:32.667520643 -0500
71 71
ssh_exec_and_log "$DST_HOST" "rm -rf '$DST_PATH'" \
72 72
    "Error removing target path to prevent overwrite errors"
73 73

  
74
TAR_COPY="$SSH $SRC_HOST '$TAR -C $SRC_DS_DIR --sparse -cf - $SRC_VM_DIR'"
75
TAR_COPY="$TAR_COPY | $SSH $DST_HOST '$TAR -C $DST_DIR --sparse -xf -'"
74
TAR_COPY="$SSH $SRC_HOST '$SUDO $TAR -C $SRC_DS_DIR --sparse -cf - $SRC_VM_DIR | $SSH $DST_HOST '\''$SUDO $TAR -C $DST_DIR --sparse -xf -'\'''"
76 75

  
77 76
exec_and_log "eval $TAR_COPY" "Error copying disk directory to target host"
78 77

  
opennebula-4.90.5-runasuser/src/vmm/LibVirtDriverKVM.cc 2016-06-06 10:59:32.667520643 -0500
230 230
         << " xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>"
231 231
         << endl;
232 232

  
233
    /* Domain user information */
234
    file << "\t<seclabel type='static' model='dac'>" << endl;
235
    file << "\t\t<label>+" << (vm->get_oid() + 131072) << ":+" << (vm->get_oid() + 131072) << "</label>" << endl;
236
    file << "\t</seclabel>" << endl;
237

  
233 238
    // ------------------------------------------------------------------------
234 239
    // Domain name
235 240
    // ------------------------------------------------------------------------
opennebula-4.90.5-runasuser/src/vmm_mad/remotes/kvm/restore 2016-06-07 11:39:31.767876969 -0500
28 28
VM_ID=$4
29 29
DS_ID=$5
30 30

  
31
# This computation is a duplicate of what is performed in LibVirtDriverKVM.cc
32
vmuid=$[131072+$VM_ID]
33
vmgid="${vmuid}"
34

  
31 35
FILE_XML=${FILE}.xml
32 36

  
33 37
#-------------------------------------------------------------------------------
opennebula-4.90.5-runasuser/src/vmm_mad/remotes/kvm/save 2016-06-07 11:41:08.826876815 -0500
36 36
fi
37 37

  
38 38
touch "$FILE"
39
chmod 666 "$FILE"
39
chmod 600 "$FILE"
40 40

  
41 41
exec_and_log "virsh --connect $LIBVIRT_URI save $DEPLOY_ID $FILE" \
42 42
    "Could not save $DEPLOY_ID to $FILE"