debuggers.hg

view tools/libxl/libxl_utils.h @ 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 6874a9d26fd9
children 4fea7664a6fb
line source
1 /*
2 * Copyright (C) 2009 Citrix Ltd.
3 * Author Stefano Stabellini <stefano.stabellini@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 #ifndef LIBXL_UTILS_H
17 #define LIBXL_UTILS_H
19 #include "libxl.h"
21 const char *libxl_basename(const char *name); /* returns string from strdup */
22 unsigned long libxl_get_required_shadow_memory(unsigned long maxmem_kb, unsigned int smp_cpus);
23 int libxl_name_to_domid(libxl_ctx *ctx, const char *name, uint32_t *domid);
24 char *libxl_domid_to_name(libxl_ctx *ctx, uint32_t domid);
25 int libxl_name_to_cpupoolid(libxl_ctx *ctx, const char *name, uint32_t *poolid);
26 char *libxl_cpupoolid_to_name(libxl_ctx *ctx, uint32_t poolid);
27 int libxl_name_to_schedid(libxl_ctx *ctx, const char *name);
28 char *libxl_schedid_to_name(libxl_ctx *ctx, int schedid);
29 int libxl_get_stubdom_id(libxl_ctx *ctx, int guest_domid);
30 int libxl_is_stubdom(libxl_ctx *ctx, uint32_t domid, uint32_t *target_domid);
31 int libxl_create_logfile(libxl_ctx *ctx, char *name, char **full_name);
32 int libxl_string_to_phystype(libxl_ctx *ctx, char *s, libxl_disk_phystype *phystype);
34 int libxl_read_file_contents(libxl_ctx *ctx, const char *filename,
35 void **data_r, int *datalen_r);
36 /* Reads the contents of the plain file filename into a mallocd
37 * buffer. Returns 0 or errno. Any errors other than ENOENT are logged.
38 * If the file is empty, *data_r and *datalen_r are set to 0.
39 * On error, *data_r and *datalen_r are undefined.
40 * data_r and/or datalen_r may be 0.
41 */
43 int libxl_read_exactly(libxl_ctx *ctx, int fd, void *data, ssize_t sz,
44 const char *filename, const char *what);
45 int libxl_write_exactly(libxl_ctx *ctx, int fd, const void *data,
46 ssize_t sz, const char *filename, const char *what);
47 /* Returns 0 or errno. If file is truncated on reading, returns
48 * EPROTO and you have no way to tell how much was read. Errors are
49 * logged using filename (which is only used for logging) and what
50 * (which may be 0). */
52 pid_t libxl_fork(libxl_ctx *ctx);
53 int libxl_pipe(libxl_ctx *ctx, int pipes[2]);
54 /* Just like fork(2), pipe(2), but log errors. */
56 void libxl_report_child_exitstatus(libxl_ctx *ctx, xentoollog_level,
57 const char *what, pid_t pid, int status);
58 /* treats all exit statuses as errors; if that's not what you want,
59 * check status yourself first */
61 int libxl_mac_to_device_nic(libxl_ctx *ctx, uint32_t domid,
62 const char *mac, libxl_device_nic *nic);
63 int libxl_devid_to_device_nic(libxl_ctx *ctx, uint32_t domid,
64 const char *devid, libxl_device_nic *nic);
66 int libxl_devid_to_device_disk(libxl_ctx *ctx, uint32_t domid,
67 const char *devid, libxl_device_disk *disk);
69 int libxl_strtomac(const char *mac_s, uint8_t *mac);
71 int libxl_devid_to_device_net2(libxl_ctx *ctx, uint32_t domid,
72 const char *devid, libxl_device_net2 *net2);
74 /* check the version of qemu
75 * return 1 if is the new one
76 * return 0 if is the old one
77 * return -1 if there are an error */
78 int libxl_check_device_model_version(libxl_ctx *ctx, char *path);
80 int libxl_cpumap_alloc(libxl_ctx *ctx, libxl_cpumap *cpumap);
81 int libxl_cpumap_test(libxl_cpumap *cpumap, int cpu);
82 void libxl_cpumap_set(libxl_cpumap *cpumap, int cpu);
83 void libxl_cpumap_reset(libxl_cpumap *cpumap, int cpu);
84 #define libxl_for_each_cpu(var, map) for (var = 0; var < (map).size * 8; var++)
86 int libxl_cpuarray_alloc(libxl_ctx *ctx, libxl_cpuarray *cpuarray);
88 static inline uint32_t libxl__sizekb_to_mb(uint32_t s) {
89 return (s + 1023) / 1024;
90 }
92 #endif