~ubuntu-branches/ubuntu/maverick/libvirt/maverick

« back to all changes in this revision

Viewing changes to src/storage_backend_fs.c

  • Committer: Bazaar Package Importer
  • Author(s): Soren Hansen
  • Date: 2008-06-25 18:51:21 UTC
  • mto: (3.1.1 lenny) (1.2.1 upstream) (0.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 27.
  • Revision ID: james.westby@ubuntu.com-20080625185121-8dku38gpoluks1bx
Tags: upstream-0.4.4
ImportĀ upstreamĀ versionĀ 0.4.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
#include <mntent.h>
37
37
#include <string.h>
38
38
 
 
39
#include "internal.h"
39
40
#include "storage_backend_fs.h"
40
41
#include "storage_conf.h"
41
42
#include "util.h"
42
 
#include "config.h"
43
 
 
 
43
#include "memory.h"
44
44
 
45
45
enum {
46
46
    VIR_STORAGE_POOL_FS_AUTO = 0,
79
79
};
80
80
 
81
81
/* Either 'magic' or 'extension' *must* be provided */
82
 
struct {
 
82
struct FileTypeInfo {
83
83
    int type;           /* One of the constants above */
84
84
    const char *magic;  /* Optional string of file magic
85
85
                         * to check at head of file */
94
94
                           * -1 to use st_size as capacity */
95
95
    int sizeBytes;        /* Number of bytes for size field */
96
96
    int sizeMultiplier;   /* A scaling factor if size is not in bytes */
97
 
} fileTypeInfo[] = {
 
97
};
 
98
const struct FileTypeInfo const fileTypeInfo[] = {
98
99
    /* Bochs */
99
100
    /* XXX Untested
100
101
    { VIR_STORAGE_VOL_BOCHS, "Bochs Virtual HD Image", NULL,
528
529
    }
529
530
 
530
531
    if (pool->def->type == VIR_STORAGE_POOL_NETFS) {
531
 
        src = malloc(strlen(pool->def->source.host.name) +
532
 
                     1 + strlen(pool->def->source.dir) + 1);
 
532
        if (VIR_ALLOC_N(src, strlen(pool->def->source.host.name) +
 
533
                        1 + strlen(pool->def->source.dir) + 1) < 0) {
 
534
            virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("source"));
 
535
            return -1;
 
536
        }
533
537
        strcpy(src, pool->def->source.host.name);
534
538
        strcat(src, ":");
535
539
        strcat(src, pool->def->source.dir);
536
540
    } else {
537
 
        src = strdup(pool->def->source.devices[0].path);
538
 
    }
539
 
    if (src == NULL) {
540
 
        virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("source"));
541
 
        return -1;
 
541
        if ((src = strdup(pool->def->source.devices[0].path)) == NULL) {
 
542
            virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("source"));
 
543
            return -1;
 
544
        }
542
545
    }
543
546
    mntargv[3] = src;
544
547
 
545
548
    if (virRun(conn, (char**)mntargv, NULL) < 0) {
546
 
        free(src);
 
549
        VIR_FREE(src);
547
550
        return -1;
548
551
    }
549
 
    free(src);
 
552
    VIR_FREE(src);
550
553
    return 0;
551
554
}
552
555
 
677
680
        virStorageVolDefPtr vol;
678
681
        int ret;
679
682
 
680
 
        vol = calloc(1, sizeof(virStorageVolDef));
681
 
        if (vol == NULL) {
 
683
        if (VIR_ALLOC(vol) < 0) {
682
684
            virStorageReportError(conn, VIR_ERR_NO_MEMORY,
683
685
                                  "%s", _("volume"));
684
686
            goto cleanup;
686
688
 
687
689
        vol->name = strdup(ent->d_name);
688
690
        if (vol->name == NULL) {
689
 
            free(vol);
 
691
            VIR_FREE(vol);
690
692
            virStorageReportError(conn, VIR_ERR_NO_MEMORY,
691
693
                                  "%s", _("volume name"));
692
694
            goto cleanup;
693
695
        }
694
696
 
695
697
        vol->target.format = VIR_STORAGE_VOL_RAW; /* Real value is filled in during probe */
696
 
        vol->target.path = malloc(strlen(pool->def->target.path) +
697
 
                                  1 + strlen(vol->name) + 1);
698
 
        if (vol->target.path == NULL) {
699
 
            free(vol->target.path);
700
 
            free(vol);
 
698
        if (VIR_ALLOC_N(vol->target.path, strlen(pool->def->target.path) +
 
699
                        1 + strlen(vol->name) + 1) < 0) {
 
700
            VIR_FREE(vol->target.path);
 
701
            VIR_FREE(vol);
701
702
            virStorageReportError(conn, VIR_ERR_NO_MEMORY,
702
703
                                  "%s", _("volume name"));
703
704
            goto cleanup;
706
707
        strcat(vol->target.path, "/");
707
708
        strcat(vol->target.path, vol->name);
708
709
        if ((vol->key = strdup(vol->target.path)) == NULL) {
709
 
            free(vol->name);
710
 
            free(vol->target.path);
711
 
            free(vol);
 
710
            VIR_FREE(vol->name);
 
711
            VIR_FREE(vol->target.path);
 
712
            VIR_FREE(vol);
712
713
            virStorageReportError(conn, VIR_ERR_NO_MEMORY,
713
714
                                  "%s", _("volume key"));
714
715
            goto cleanup;
715
716
        }
716
717
 
717
718
        if ((ret = virStorageBackendProbeFile(conn, vol) < 0)) {
718
 
            free(vol->key);
719
 
            free(vol->name);
720
 
            free(vol->target.path);
721
 
            free(vol);
 
719
            VIR_FREE(vol->key);
 
720
            VIR_FREE(vol->name);
 
721
            VIR_FREE(vol->target.path);
 
722
            VIR_FREE(vol);
722
723
            if (ret == -1)
723
724
                goto cleanup;
724
725
            else
819
820
{
820
821
    int fd;
821
822
 
822
 
    vol->target.path = malloc(strlen(pool->def->target.path) +
823
 
                              1 + strlen(vol->name) + 1);
824
 
    if (vol->target.path == NULL) {
 
823
    if (VIR_ALLOC_N(vol->target.path, strlen(pool->def->target.path) +
 
824
                    1 + strlen(vol->name) + 1) < 0) {
825
825
        virStorageReportError(conn, VIR_ERR_NO_MEMORY, "%s", _("target"));
826
826
        return -1;
827
827
    }
1108
1108
    .volType = VIR_STORAGE_VOL_FILE,
1109
1109
};
1110
1110
#endif /* WITH_STORAGE_FS */
1111
 
 
1112
 
/*
1113
 
 * vim: set tabstop=4:
1114
 
 * vim: set shiftwidth=4:
1115
 
 * vim: set expandtab:
1116
 
 */
1117
 
/*
1118
 
 * Local variables:
1119
 
 *  indent-tabs-mode: nil
1120
 
 *  c-indent-level: 4
1121
 
 *  c-basic-offset: 4
1122
 
 *  tab-width: 4
1123
 
 * End:
1124
 
 */