debuggers.hg

view tools/libxl/libxl_xshelp.c @ 22855:1d1eec7e1fb4

xl: Perform minimal validation of virtual disk file while parsing config file

This patch performs some very basic validation on the virtual disk
file passed through the config file. This validation ensures that we
don't go too far with the initialization like spawn qemu and more
while there could be some potentially fundamental issues.

[ Patch fixed up to work with PHYSTYPE_EMPTY 22808:6ec61438713a -iwj ]

Signed-off-by: Kamala Narasimhan <kamala.narasimhan@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
author Kamala Narasimhan <kamala.narasimhan@gmail.com>
date Tue Jan 25 18:09:49 2011 +0000 (2011-01-25)
parents 606b0eb2caa7
children
line source
1 /*
2 * Copyright (C) 2009 Citrix Ltd.
3 * Author Vincent Hanquez <vincent.hanquez@eu.citrix.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation; version 2.1 only. with the special
8 * exception on linking described in file LICENSE.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 */
16 #include "libxl_osdeps.h"
18 #include <string.h>
19 #include <stddef.h>
20 #include <stdio.h>
21 #include <stdarg.h>
22 #include <inttypes.h>
24 #include "libxl.h"
25 #include "libxl_internal.h"
27 char **libxl__xs_kvs_of_flexarray(libxl__gc *gc, flexarray_t *array, int length)
28 {
29 char **kvs;
30 int i;
32 if (!length)
33 return NULL;
35 kvs = libxl__calloc(gc, length + 2, sizeof(char *));
36 if (kvs) {
37 for (i = 0; i < length; i += 2) {
38 void *ptr;
40 flexarray_get(array, i, &ptr);
41 kvs[i] = (char *) ptr;
42 flexarray_get(array, i + 1, &ptr);
43 kvs[i + 1] = (char *) ptr;
44 }
45 kvs[i] = NULL;
46 kvs[i + 1] = NULL;
47 }
48 return kvs;
49 }
51 int libxl__xs_writev(libxl__gc *gc, xs_transaction_t t,
52 char *dir, char *kvs[])
53 {
54 libxl_ctx *ctx = libxl__gc_owner(gc);
55 char *path;
56 int i;
58 if (!kvs)
59 return 0;
61 for (i = 0; kvs[i] != NULL; i += 2) {
62 path = libxl__sprintf(gc, "%s/%s", dir, kvs[i]);
63 if (path && kvs[i + 1]) {
64 int length = strlen(kvs[i + 1]);
65 xs_write(ctx->xsh, t, path, kvs[i + 1], length);
66 }
67 }
68 return 0;
69 }
71 int libxl__xs_write(libxl__gc *gc, xs_transaction_t t,
72 char *path, char *fmt, ...)
73 {
74 libxl_ctx *ctx = libxl__gc_owner(gc);
75 char *s;
76 va_list ap;
77 int ret;
78 va_start(ap, fmt);
79 ret = vasprintf(&s, fmt, ap);
80 va_end(ap);
82 if (ret == -1) {
83 return -1;
84 }
85 xs_write(ctx->xsh, t, path, s, ret);
86 free(s);
87 return 0;
88 }
90 char * libxl__xs_read(libxl__gc *gc, xs_transaction_t t, char *path)
91 {
92 libxl_ctx *ctx = libxl__gc_owner(gc);
93 char *ptr;
95 ptr = xs_read(ctx->xsh, t, path, NULL);
96 if (ptr != NULL) {
97 libxl__ptr_add(gc, ptr);
98 return ptr;
99 }
100 return 0;
101 }
103 char *libxl__xs_get_dompath(libxl__gc *gc, uint32_t domid)
104 {
105 libxl_ctx *ctx = libxl__gc_owner(gc);
106 char *s = xs_get_domain_path(ctx->xsh, domid);
107 if (!s) {
108 LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "failed to get dompath for %" PRIu32,
109 domid);
110 return NULL;
111 }
112 libxl__ptr_add(gc, s);
113 return s;
114 }
116 char **libxl__xs_directory(libxl__gc *gc, xs_transaction_t t, char *path, unsigned int *nb)
117 {
118 libxl_ctx *ctx = libxl__gc_owner(gc);
119 char **ret = NULL;
120 ret = xs_directory(ctx->xsh, XBT_NULL, path, nb);
121 libxl__ptr_add(gc, ret);
122 return ret;
123 }