Skip to content

Commit ccdc4f4

Browse files
committed
Xen 4.1: Preliminary adjust on xenguest
Signed-off-by: Gianni Tedesco <[email protected]> Signed-off-by: Zheng Li <[email protected]>
1 parent 52dd900 commit ccdc4f4

File tree

2 files changed

+39
-91
lines changed

2 files changed

+39
-91
lines changed

ocaml/xenguest/save_helpers.c

Lines changed: 27 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,9 @@
4040

4141
static char *qemu_active_path;
4242
static char *qemu_next_active_path;
43-
static int qemu_shmid = -1;
4443
static struct xs_handle *xs;
4544

4645

47-
/* Mark the shared-memory segment for destruction */
48-
static void qemu_destroy_buffer(void)
49-
{
50-
if (qemu_shmid != -1)
51-
shmctl(qemu_shmid, IPC_RMID, NULL);
52-
qemu_shmid = -1;
53-
}
54-
5546
/* Get qemu to change buffers. */
5647
void qemu_flip_buffer(int domid, int next_active)
5748
{
@@ -61,6 +52,33 @@ void qemu_flip_buffer(int domid, int next_active)
6152
struct timeval tv;
6253
fd_set fdset;
6354
int rc;
55+
char *path, *p;
56+
57+
if (xs == NULL) {
58+
if ((xs = xs_daemon_open()) == NULL)
59+
errx(1, "Couldn't contact xenstore");
60+
if (!(path = xs_get_domain_path(xs, domid)))
61+
errx(1, "can't get domain path in store");
62+
if (!(path = realloc(path, strlen(path)
63+
+ strlen("/logdirty/next-active") + 1)))
64+
errx(1, "no memory for constructing xenstore path");
65+
strcat(path, "/logdirty/");
66+
p = path + strlen(path);
67+
68+
/* Watch for qemu's indication of the active buffer, and request it
69+
* to start writing to buffer 0 */
70+
strcpy(p, "active");
71+
if (!xs_watch(xs, path, "qemu-active-buffer"))
72+
errx(1, "can't set watch in store (%s)\n", path);
73+
if (!(qemu_active_path = strdup(path)))
74+
errx(1, "no memory for copying xenstore path");
75+
76+
strcpy(p, "next-active");
77+
if (!(qemu_next_active_path = strdup(path)))
78+
errx(1, "no memory for copying xenstore path");
79+
80+
free(path);
81+
}
6482

6583
/* Tell qemu that we want it to start writing log-dirty bits to the
6684
* other buffer */
@@ -94,78 +112,4 @@ void qemu_flip_buffer(int domid, int next_active)
94112
goto read_again;
95113
}
96114

97-
void * init_qemu_maps(int domid, unsigned int bitmap_size)
98-
{
99-
key_t key;
100-
char key_ascii[17] = {0,};
101-
void *seg;
102-
char *path, *p;
103-
struct shmid_ds ds_buf;
104-
struct group *gr;
105-
106-
/* Make a shared-memory segment */
107-
do {
108-
key = rand(); /* No security, just a sequence of numbers */
109-
qemu_shmid = shmget(key, 2 * bitmap_size,
110-
IPC_CREAT|IPC_EXCL|S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP);
111-
if (qemu_shmid == -1 && errno != EEXIST)
112-
errx(1, "can't get shmem to talk to qemu-dm");
113-
} while (qemu_shmid == -1);
114-
115-
/* Remember to tidy up after ourselves */
116-
atexit(qemu_destroy_buffer);
117-
118-
/* Change owner so that qemu can map it. */
119-
gr = getgrnam("qemu_base");
120-
if (!gr)
121-
err(1, "can't get qemu gid");
122-
if (shmctl(qemu_shmid, IPC_STAT, &ds_buf) < 0)
123-
err(1, "can't get status of shm area");
124-
ds_buf.shm_perm.gid = gr->gr_gid + (unsigned short)domid;
125-
if (shmctl(qemu_shmid, IPC_SET, &ds_buf) < 0)
126-
err(1, "can't change gid of shm area");
127-
128-
/* Map it into our address space */
129-
seg = shmat(qemu_shmid, NULL, 0);
130-
if (seg == (void *) -1)
131-
errx(1, "can't map shmem to talk to qemu-dm");
132-
memset(seg, 0, 2 * bitmap_size);
133-
134-
/* Write the size of it into the first 32 bits */
135-
*(uint32_t *)seg = bitmap_size;
136-
137-
/* Tell qemu about it */
138-
if ((xs = xs_daemon_open()) == NULL)
139-
errx(1, "Couldn't contact xenstore");
140-
if (!(path = xs_get_domain_path(xs, domid)))
141-
errx(1, "can't get domain path in store");
142-
if (!(path = realloc(path, strlen(path)
143-
+ strlen("/logdirty/next-active") + 1)))
144-
errx(1, "no memory for constructing xenstore path");
145-
strcat(path, "/logdirty/");
146-
p = path + strlen(path);
147-
148-
strcpy(p, "key");
149-
snprintf(key_ascii, 17, "%16.16llx", (unsigned long long) key);
150-
if (!xs_write(xs, XBT_NULL, path, key_ascii, 16))
151-
errx(1, "can't write key (%s) to store path (%s)\n", key_ascii, path);
152-
153-
/* Watch for qemu's indication of the active buffer, and request it
154-
* to start writing to buffer 0 */
155-
strcpy(p, "active");
156-
if (!xs_watch(xs, path, "qemu-active-buffer"))
157-
errx(1, "can't set watch in store (%s)\n", path);
158-
if (!(qemu_active_path = strdup(path)))
159-
errx(1, "no memory for copying xenstore path");
160-
161-
strcpy(p, "next-active");
162-
if (!(qemu_next_active_path = strdup(path)))
163-
errx(1, "no memory for copying xenstore path");
164-
165-
qemu_flip_buffer(domid, 0);
166-
167-
free(path);
168-
return seg;
169-
}
170-
171115
/***********************************************************************/

ocaml/xenguest/xenguest_stubs.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,10 @@ static void failwith_oss_xc(char *fct)
152152
caml_failwith(buf);
153153
}
154154

155-
static int dispatch_suspend(int domid)
155+
static int dispatch_suspend(void *arg)
156156
{
157157
value * __suspend_closure;
158+
int domid = (int) arg;
158159
int ret;
159160

160161
__suspend_closure = caml_named_value("suspend_callback");
@@ -194,7 +195,7 @@ static void configure_vcpus(int handle, int domid, struct flags f){
194195
int i, r;
195196
if (f.vcpu_affinity != 0L){ /* 0L means unset */
196197
for (i=0; i<f.vcpus; i++){
197-
r = xc_vcpu_setaffinity(handle, domid, i, f.vcpu_affinity);
198+
r = xc_vcpu_setaffinity(handle, domid, i, &f.vcpu_affinity, sizeof f.vcpu_affinity);
198199
if (r)
199200
failwith_oss_xc("xc_vcpu_setaffinity");
200201
}
@@ -367,29 +368,32 @@ CAMLprim value stub_xc_hvm_build_bytecode(value * argv, int argn)
367368
}
368369

369370
extern void qemu_flip_buffer(int domid, int next_active);
370-
extern void * init_qemu_maps(int domid, unsigned int bitmap_size);
371+
372+
static struct save_callbacks save_callbacks = {
373+
.suspend = dispatch_suspend,
374+
.postcopy = NULL,
375+
.checkpoint = NULL,
376+
};
371377

372378
CAMLprim value stub_xc_domain_save(value handle, value fd, value domid,
373379
value max_iters, value max_factors,
374380
value flags, value hvm)
375381
{
376382
CAMLparam5(handle, fd, domid, max_iters, max_factors);
377383
CAMLxparam2(flags, hvm);
378-
void *(*init_maps)(int, unsigned);
379384
void (*flip_buffer)(int, int);
380385
uint32_t c_flags;
381386
int r;
382387

383-
init_maps = (Bool_val(hvm)) ? init_qemu_maps : NULL;
384388
flip_buffer = (Bool_val(hvm)) ? qemu_flip_buffer : NULL;
385389

386390
c_flags = caml_convert_flag_list(flags, suspend_flag_list);
387391

388392
caml_enter_blocking_section();
389393
r = xc_domain_save(_H(handle), Int_val(fd), _D(domid),
390394
Int_val(max_iters), Int_val(max_factors),
391-
c_flags, dispatch_suspend,
392-
Bool_val(hvm), init_maps, flip_buffer);
395+
c_flags, &save_callbacks,
396+
Bool_val(hvm), flip_buffer);
393397
caml_leave_blocking_section();
394398
if (r)
395399
failwith_oss_xc("xc_domain_save");
@@ -444,7 +448,7 @@ CAMLprim value stub_xc_domain_restore(value handle, value fd, value domid,
444448
r = xc_domain_restore(_H(handle), Int_val(fd), _D(domid),
445449
c_store_evtchn, &store_mfn,
446450
c_console_evtchn, &console_mfn,
447-
Bool_val(hvm), f.pae);
451+
Bool_val(hvm), f.pae, Bool_val(hvm));
448452
caml_leave_blocking_section();
449453
if (r)
450454
failwith_oss_xc("xc_domain_restore");

0 commit comments

Comments
 (0)