ia64/xen-unstable

view tools/libfsimage/common/fsimage_plugin.c @ 19848:5839491bbf20

[IA64] replace MAX_VCPUS with d->max_vcpus where necessary.

don't use MAX_VCPUS, and use vcpu::max_vcpus.
The changeset of 2f9e1348aa98 introduced max_vcpus to allow more vcpus
per guest. This patch is ia64 counter part.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Isaku Yamahata <yamahata@valinux.co.jp>
date Mon Jun 29 11:26:05 2009 +0900 (2009-06-29)
parents 2c48ed7e303d
children
line source
1 /*
2 * Permission is hereby granted, free of charge, to any person obtaining a copy
3 * of this software and associated documentation files (the "Software"), to
4 * deal in the Software without restriction, including without limitation the
5 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
6 * sell copies of the Software, and to permit persons to whom the Software is
7 * furnished to do so, subject to the following conditions:
8 *
9 * The above copyright notice and this permission notice shall be included in
10 * all copies or substantial portions of the Software.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
17 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
18 * DEALINGS IN THE SOFTWARE.
19 *
20 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
21 * Use is subject to license terms.
22 */
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <strings.h>
27 #include <string.h>
28 #include <dirent.h>
29 #include <dlfcn.h>
30 #include <errno.h>
32 #include "fsimage_plugin.h"
33 #include "fsimage_priv.h"
35 static fsi_plugin_t *plugins;
37 void
38 fsip_fs_set_data(fsi_t *fsi, void *data)
39 {
40 fsi->f_data = data;
41 }
43 fsi_file_t *
44 fsip_file_alloc(fsi_t *fsi, void *data)
45 {
46 fsi_file_t *ffi = malloc(sizeof (fsi_file_t));
47 if (ffi == NULL)
48 return (NULL);
50 bzero(ffi, sizeof (fsi_file_t));
52 ffi->ff_fsi = fsi;
53 ffi->ff_data = data;
54 return (ffi);
55 }
57 void
58 fsip_file_free(fsi_file_t *ffi)
59 {
60 free(ffi);
61 }
63 fsi_t *
64 fsip_fs(fsi_file_t *ffi)
65 {
66 return (ffi->ff_fsi);
67 }
69 uint64_t
70 fsip_fs_offset(fsi_t *fsi)
71 {
72 return (fsi->f_off);
73 }
75 void *
76 fsip_fs_data(fsi_t *fsi)
77 {
78 return (fsi->f_data);
79 }
81 void *
82 fsip_file_data(fsi_file_t *ffi)
83 {
84 return (ffi->ff_data);
85 }
87 static int init_plugin(const char *lib)
88 {
89 fsi_plugin_init_t init;
90 fsi_plugin_t *fp = malloc(sizeof (fsi_plugin_t));
92 if (fp == NULL)
93 return (-1);
95 bzero(fp, sizeof (fsi_plugin_t));
97 if ((fp->fp_dlh = dlopen(lib, RTLD_LAZY | RTLD_LOCAL)) == NULL) {
98 free(fp);
99 return (0);
100 }
102 init = dlsym(fp->fp_dlh, "fsi_init_plugin");
104 if (init == NULL)
105 goto fail;
107 fp->fp_ops = init(FSIMAGE_PLUGIN_VERSION, fp, &fp->fp_name);
108 if (fp->fp_ops == NULL ||
109 fp->fp_ops->fpo_version > FSIMAGE_PLUGIN_VERSION)
110 goto fail;
112 fp->fp_next = plugins;
113 plugins = fp;
115 return (0);
116 fail:
117 (void) dlclose(fp->fp_dlh);
118 free(fp);
119 return (-1);
120 }
122 static int load_plugins(void)
123 {
124 const char *fsdir = getenv("FSIMAGE_FSDIR");
125 const char *isadir = "";
126 struct dirent *dp = NULL;
127 struct dirent *dpp;
128 DIR *dir = NULL;
129 char *tmp = NULL;
130 size_t name_max;
131 int err;
132 int ret = -1;
134 #if defined(FSIMAGE_FSDIR)
135 if (fsdir == NULL)
136 fsdir = FSIMAGE_FSDIR;
137 #elif defined(__sun__)
138 if (fsdir == NULL)
139 fsdir = "/usr/lib/fs";
141 if (sizeof(void *) == 8)
142 isadir = "64/";
143 #elif defined(__ia64__)
144 if (fsdir == NULL)
145 fsdir = "/usr/lib/fs";
146 #else
147 if (fsdir == NULL) {
148 if (sizeof(void *) == 8)
149 fsdir = "/usr/lib64/fs";
150 else
151 fsdir = "/usr/lib/fs";
152 }
153 #endif
155 if ((name_max = pathconf(fsdir, _PC_NAME_MAX)) == -1)
156 goto fail;
158 if ((tmp = malloc(name_max + 1)) == NULL)
159 goto fail;
161 if ((dp = malloc(sizeof (struct dirent) + name_max + 1)) == NULL)
162 goto fail;
164 if ((dir = opendir(fsdir)) == NULL)
165 goto fail;
167 bzero(dp, sizeof (struct dirent) + name_max + 1);
169 while (readdir_r(dir, dp, &dpp) == 0 && dpp != NULL) {
170 if (strcmp(dpp->d_name, ".") == 0)
171 continue;
172 if (strcmp(dpp->d_name, "..") == 0)
173 continue;
175 (void) snprintf(tmp, name_max, "%s/%s/%sfsimage.so", fsdir,
176 dpp->d_name, isadir);
178 if (init_plugin(tmp) != 0)
179 goto fail;
180 }
182 ret = 0;
184 fail:
185 err = errno;
186 if (dir != NULL)
187 (void) closedir(dir);
188 free(tmp);
189 free(dp);
190 errno = err;
191 return (ret);
192 }
194 int find_plugin(fsi_t *fsi, const char *path, const char *options)
195 {
196 fsi_plugin_t *fp;
197 int ret = 0;
199 if (plugins == NULL && (ret = load_plugins()) != 0)
200 goto out;
202 for (fp = plugins; fp != NULL; fp = fp->fp_next) {
203 fsi->f_plugin = fp;
204 if (fp->fp_ops->fpo_mount(fsi, path, options) == 0)
205 goto out;
206 }
208 ret = -1;
209 errno = ENOTSUP;
210 out:
211 return (ret);
212 }