Howdy.

Attached patch allows vmd to fail fast on unknown disk format along with
some minor clean up on logging.

Comments? Ok?

+--+
Carlos
Index: vioqcow2.c
===================================================================
RCS file: /home/los/cvs/src/usr.sbin/vmd/vioqcow2.c,v
retrieving revision 1.1
diff -u -p -r1.1 vioqcow2.c
--- vioqcow2.c  9 Sep 2018 04:09:32 -0000       1.1
+++ vioqcow2.c  11 Sep 2018 02:42:11 -0000
@@ -127,7 +127,7 @@ virtio_init_qcow2(struct virtio_backing 
        if (diskp == NULL)
                return -1;
        if (qc2_open(diskp, fd) == -1) {
-               log_warnx("could not open qcow2 disk");
+               log_warnx("%s: could not open qcow2 disk", __func__);
                free(diskp);
                return -1;
        }
@@ -162,11 +162,11 @@ qc2_open(struct qcdisk *disk, int fd)
        int version;
 
        if (pread(fd, &header, sizeof header, 0) != sizeof header) {
-               log_warn("short read on header");
+               log_warn("%s: short read on header", __func__);
                return -1;
        }
        if (strncmp(header.magic, "QFI\xfb", 4) != 0) {
-               log_warn("invalid magic numbers");
+               log_warn("%s: invalid magic numbers", __func__);
                return -1;
        }
        pthread_rwlock_init(&disk->lock, NULL);
@@ -196,7 +196,7 @@ qc2_open(struct qcdisk *disk, int fd)
         * We only know about the dirty or corrupt bits here.
         */
        if (disk->incompatfeatures & ~(QCOW2_DIRTY|QCOW2_CORRUPT)) {
-               log_warn("%s: unsupported features %llx", __progname,
+               log_warn("%s: unsupported features %llx", __func__,
                    disk->incompatfeatures & ~(QCOW2_DIRTY|QCOW2_CORRUPT));
                return -1;
        }
@@ -211,7 +211,7 @@ qc2_open(struct qcdisk *disk, int fd)
                disk->l1[i] = be64toh(disk->l1[i]);
        version = be32toh(header.version);
        if (version != 2 && version != 3) {
-               log_warn("%s: unknown qcow2 version %d", __progname, version);
+               log_warn("%s: unknown qcow2 version %d", __func__, version);
                return -1;
        }
 
@@ -222,16 +222,16 @@ qc2_open(struct qcdisk *disk, int fd)
                 * FIXME: we need to figure out a way of opening these things,
                 * otherwise we just crash with a pledge violation.
                 */
-               log_warn("unsupported external snapshot images");
+               log_warn("%s: unsupported external snapshot images", __func__);
                return -1;
 
                if (backingsz >= sizeof basepath - 1) {
-                       log_warn("%s: snapshot path too long", __progname);
+                       log_warn("%s: snapshot path too long", __func__);
                        return -1;
                }
                if (pread(fd, basepath, backingsz, backingoff) != backingsz) {
                        log_warn("%s: could not read snapshot base name",
-                           __progname);
+                           __func__);
                        return -1;
                }
                basepath[backingsz] = 0;
@@ -243,7 +243,7 @@ qc2_open(struct qcdisk *disk, int fd)
                }
                if (disk->base->clustersz != disk->clustersz) {
                        log_warn("%s: all disks must share clustersize",
-                           __progname);
+                           __func__);
                        free(disk->base);
                        return -1;
                }
@@ -414,7 +414,7 @@ xlate(struct qcdisk *disk, off_t off, in
        if (inplace)
                *inplace = !!(cluster & QCOW2_INPLACE);
        if (cluster & QCOW2_COMPRESSED) {
-               log_warn("%s: compressed clusters unsupported", __progname);
+               log_warn("%s: compressed clusters unsupported", __func__);
                goto err;
        }
        pthread_rwlock_unlock(&disk->lock);
@@ -556,7 +556,7 @@ inc_refs(struct qcdisk *disk, off_t off,
                l2cluster = disk->end;
                disk->end += disk->clustersz;
                if (ftruncate(disk->fd, disk->end) < 0) {
-                       log_warn("refs block grow fail ");
+                       log_warn("%s: refs block grow fail", __func__);
                        return -1;
                }
                buf = htobe64(l2cluster);
@@ -573,7 +573,7 @@ inc_refs(struct qcdisk *disk, off_t off,
        }
        refs = htobe16(refs);
        if (pwrite(disk->fd, &refs, sizeof refs, l2cluster + 2*l2idx) != 2) {
-               log_warn("could not write ref block");
+               log_warn("%s: could not write ref block", __func__);
        }
        return 0;
 }
Index: virtio.c
===================================================================
RCS file: /home/los/cvs/src/usr.sbin/vmd/virtio.c,v
retrieving revision 1.65
diff -u -p -r1.65 virtio.c
--- virtio.c    9 Sep 2018 04:09:32 -0000       1.65
+++ virtio.c    11 Sep 2018 02:51:37 -0000
@@ -1756,7 +1756,7 @@ virtio_init_disk(struct virtio_backing *
        case VMDF_RAW:          return virtio_init_raw(file, sz, fd);
        case VMDF_QCOW2:        return virtio_init_qcow2(file, sz, fd);
        }
-       log_warnx("%s: invalid disk format", __progname);
+       log_warnx("%s: invalid disk format", __func__);
        return -1;
 }
 
@@ -1838,8 +1838,11 @@ virtio_init(struct vmd_vm *vm, int child
                        vioblk[i].vm_id = vcp->vcp_id;
                        vioblk[i].irq = pci_get_dev_irq(id);
                        if (virtio_init_disk(&vioblk[i].file, &vioblk[i].sz,
-                           child_disks[i], vmc->vmc_disktypes[i]) == -1)
-                               continue;
+                           child_disks[i], vmc->vmc_disktypes[i]) == -1) {
+                               log_warnx("%s: unable to determine disk fmt",
+                                   __func__);
+                               return;
+                       }
                        vioblk[i].sz /= 512;
                }
        }
@@ -1964,8 +1967,10 @@ virtio_init(struct vmd_vm *vm, int child
                        vioscsi->vq[i].last_avail = 0;
                }
                if (virtio_init_disk(&vioscsi->file, &vioscsi->sz,
-                   child_cdrom, VMDF_RAW) == -1)
+                   child_cdrom, VMDF_RAW) == -1) {
+                       log_warnx("%s: unable to determine iso fmt", __func__);
                        return;
+               }
                vioscsi->locked = 0;
                vioscsi->lba = 0;
                vioscsi->n_blocks = vioscsi->sz >> 11; /* num of 2048 blocks in 
file */
@@ -2129,8 +2134,11 @@ vioblk_restore(int fd, struct vmop_creat
                        return (-1);
                }
                if (virtio_init_disk(&vioblk[i].file, &vioblk[i].sz,
-                    child_disks[i], vmc->vmc_disktypes[i]) == -1)
-                       continue;
+                   child_disks[i], vmc->vmc_disktypes[i]) == -1)  {
+                       log_warnx("%s: unable to determine disk fmt",
+                           __func__);
+                       return (-1);
+               }
        }
        return (0);
 }
@@ -2161,7 +2169,11 @@ vioscsi_restore(int fd, struct vm_create
                return (-1);
        }
 
-       virtio_init_disk(&vioscsi->file, &vioscsi->sz, child_cdrom, VMDF_RAW);
+       if (virtio_init_disk(&vioscsi->file, &vioscsi->sz, child_cdrom,
+           VMDF_RAW) == -1) {
+               log_warnx("%s: unable to determine iso fmt", __func__);
+               return (-1);
+       }
 
        return (0);
 }

Reply via email to