[CRIU] [PATCH 1/2] image: Move image definitions to own file
Cyrill Gorcunov
gorcunov at openvz.org
Tue May 7 15:08:35 EDT 2013
On Tue, May 07, 2013 at 10:48:33PM +0400, Pavel Emelyanov wrote:
>
> OK, let's discuss this thing. First -- image-defs.c. It contains the fdset template
> array _only_. Thus I'd name it fdset.c, but I don't understand why the rest of fdset
> management code sits outside of this file. Don't you need it?
Well, I have own compact fdset code in cpt2, which doesn't need all the stuff
we've in crtools, in particular I don't need shows and such. Thus my fdset
code is trivial
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include "xmalloc.h"
#include "fdset.h"
#include "io.h"
struct fdset *fdset_alloc(unsigned int offset, unsigned int number)
{
unsigned long len = sizeof(int) * number;
struct fdset *p = xmalloc(sizeof(*p) + len);
if (p) {
p->offset = offset;
p->number = number;
memset(p->__fd, 0xff, len);
}
return p;
}
void fdset_close(struct fdset *fdset, unsigned int from, unsigned int to)
{
unsigned int i;
for (i = from; i < to; i++) {
int *fd = fdset_fd_ptr(fdset, i);
if (!fd)
break;
close_safe(fd);
}
}
static inline void __fdset_free(struct fdset *fdset)
{
fdset_close(fdset, fdset->offset, fdset->number);
xfree(fdset);
}
void fdset_free(struct fdset **fdset)
{
if (fdset) {
__fdset_free(*fdset);
*fdset = NULL;
}
}
and that's all ;) So ideally I planned to make this fdset code to be used
in both crtools and cpt2 as shared object file, but this require more changes
to crtools, so I moved out only snippets needed (and btw, lets reserve
fdset.c for abstract file-set management not bound to crtools specifics,
iow maybe we can live with name I proposed?)
>
> The changes with cr-show.h are OK, I can merge them.
>
> The image-defs.h is the same as the .c one -- it contains parts of fdset API, thus
> it's better to name one fdset.h, but yet again -- why only parts?
Same reason, I moved only the code which really need to be shared to me. I tried
to make as minimum changes as possible.
More information about the CRIU
mailing list