Skip to content

Commit

Permalink
libct: add ability to use one library with OpenVZ and upstream kernels
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Vagin <[email protected]>
  • Loading branch information
avagin committed Nov 19, 2014
1 parent 0b5a113 commit 4c048c2
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 19 deletions.
7 changes: 0 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ cflags-y += -iquote src/lsm
cflags-y += -iquote src
cflags-y += -fno-strict-aliasing
cflags-y += -I/usr/include
ifeq ($(VZ),1)
cflags-y += -I/usr/src/kernels/$(shell uname -r)/include/
endif
export cflags-y

VERSION_MAJOR := 0
Expand Down Expand Up @@ -109,10 +106,6 @@ endif

CFLAGS += $(WARNINGS) $(DEFINES)

ifneq ("$(wildcard /proc/vz)","")
CFLAGS += -D VZ
endif

export E Q CC ECHO MAKE CFLAGS LIBS ARCH DEFINES MAKEFLAGS
export SH RM OBJCOPY LDARCH LD CP MKDIR CD LN
export ESED SED CAT
Expand Down
3 changes: 3 additions & 0 deletions src/include/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
struct _NetaddReq;
struct container;

typedef const struct ct_net_ops *(*net_get_ops_cb)(enum ct_net_type ntype);
extern ct_net_t __local_net_add(ct_handler_t h, enum ct_net_type, void *arg, net_get_ops_cb cb);

extern ct_net_t local_net_add(ct_handler_t h, enum ct_net_type, void *arg);
extern int local_net_del(ct_handler_t h, enum ct_net_type, void *arg);
extern void net_release(struct container *ct);
Expand Down
1 change: 1 addition & 0 deletions src/include/vz/vz_net.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
#include "net.h"

extern const struct ct_net_ops *vz_net_get_ops(enum ct_net_type);
extern ct_net_t vz_net_add(ct_handler_t h, enum ct_net_type ntype, void *arg);

#endif /* __LIBCT_VZ_NET_H__ */
13 changes: 7 additions & 6 deletions src/net.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static int local_net_link_apply(char *name, ct_net_t n, int pid)
return ret;
}

ct_net_t local_net_add(ct_handler_t h, enum ct_net_type ntype, void *arg)
ct_net_t __local_net_add(ct_handler_t h, enum ct_net_type ntype, void *arg, const struct ct_net_ops *(*get_ops_cb)(enum ct_net_type ntype))
{
struct container *ct = cth2ct(h);
const struct ct_net_ops *nops;
Expand All @@ -113,11 +113,7 @@ ct_net_t local_net_add(ct_handler_t h, enum ct_net_type ntype, void *arg)
if (ntype == CT_NET_NONE)
return 0;

#ifndef VZ
nops = net_get_ops(ntype);
#else
nops = vz_net_get_ops(ntype);
#endif
nops = get_ops_cb(ntype);
if (!nops)
return ERR_PTR(-LCTERR_BADTYPE);

Expand All @@ -129,6 +125,11 @@ ct_net_t local_net_add(ct_handler_t h, enum ct_net_type ntype, void *arg)
return cn;
}

ct_net_t local_net_add(ct_handler_t h, enum ct_net_type ntype, void *arg)
{
return __local_net_add(h, ntype, arg, net_get_ops);
}

int local_net_del(ct_handler_t h, enum ct_net_type ntype, void *arg)
{
struct container *ct = cth2ct(h);
Expand Down
9 changes: 4 additions & 5 deletions src/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,10 @@ libct_session_t libct_session_open_local(void)
if (s) {
INIT_LIST_HEAD(&s->s.s_cts);
INIT_LIST_HEAD(&s->s.async_list);
#ifndef VZ
s->s.ops = &local_session_ops;
#else
s->s.ops = &vz_session_ops;
#endif
if (!access("/proc/vz", F_OK))
s->s.ops = &vz_session_ops;
else
s->s.ops = &local_session_ops;
return &s->s;
}

Expand Down
2 changes: 1 addition & 1 deletion src/vz/vz.c
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,7 @@ static const struct container_ops vz_ct_ops = {
.get_state = vz_get_state,
.set_option = vz_set_option,
.set_console_fd = vz_set_console_fd,
.net_add = local_net_add,
.net_add = vz_net_add,
.net_del = local_net_del,
.net_route_add = local_net_route_add,
.uname = vz_uname,
Expand Down
5 changes: 5 additions & 0 deletions src/vz/vz_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ const struct ct_net_ops *vz_net_get_ops(enum ct_net_type ntype)
}
}

ct_net_t vz_net_add(ct_handler_t h, enum ct_net_type ntype, void *arg)
{
return __local_net_add(h, ntype, arg, vz_net_get_ops);
}

struct ct_net_veth *cn2vn(struct ct_net *n)
{
return container_of(n, struct ct_net_veth, n);
Expand Down

0 comments on commit 4c048c2

Please sign in to comment.