PERFORCE change 163063 for review
Marko Zec
zec at FreeBSD.org
Sat May 30 06:35:19 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=163063
Change 163063 by zec at zec_amdx4 on 2009/05/30 06:34:26
Reshuffle position of userspace interface handlers in vimage.c
Affected files ...
.. //depot/projects/vimage-commit2/src/sys/kern/kern_vimage.c#46 edit
Differences ...
==== //depot/projects/vimage-commit2/src/sys/kern/kern_vimage.c#46 (text+ko) ====
@@ -41,6 +41,7 @@
#include <sys/socket.h>
#include <sys/sockio.h>
#include <sys/sx.h>
+#include <sys/priv.h>
#include <sys/refcount.h>
#include <sys/vimage.h>
#ifdef DDB
@@ -66,14 +67,17 @@
#ifdef VIMAGE
static struct vimage *vimage_by_name(struct vimage *, char *);
static struct vimage *vi_alloc(struct vimage *, char *);
+static struct vimage *vimage_get_next(struct vimage *, struct vimage *, int);
+static void vimage_relative_name(struct vimage *, struct vimage *,
+ char *, int);
#endif
-#define VNET_LIST_LOCK() \
+#define VNET_LIST_WLOCK() \
mtx_lock(&vnet_list_refc_mtx); \
while (vnet_list_refc != 0) \
cv_wait(&vnet_list_condvar, &vnet_list_refc_mtx);
-#define VNET_LIST_UNLOCK() \
+#define VNET_LIST_WUNLOCK() \
mtx_unlock(&vnet_list_refc_mtx);
#ifdef VIMAGE
@@ -99,21 +103,11 @@
#endif
#ifdef VIMAGE
+
/*
- * Userspace interfaces.
+ * Interim userspace interface - will be replaced by jail soon.
*/
-int
-vi_child_of(struct vimage *parent, struct vimage *child)
-{
- if (child == parent)
- return (0);
- for (; child; child = child->vi_parent)
- if (child == parent)
- return (1);
- return (0);
-}
-
/*
* Move an ifnet to another vnet. The ifnet can be specified either
* by ifp argument, or by name contained in vi_req->vi_if_xname if NULL is
@@ -174,94 +168,6 @@
return (0);
}
-static struct vimage *
-vimage_by_name(struct vimage *top, char *name)
-{
- struct vimage *vip;
- char *next_name;
- int namelen;
-
- next_name = strchr(name, '.');
- if (next_name != NULL) {
- namelen = next_name - name;
- next_name++;
- if (namelen == 0) {
- if (strlen(next_name) == 0)
- return(top); /* '.' == this vimage */
- else
- return(NULL);
- }
- } else
- namelen = strlen(name);
- if (namelen == 0)
- return(NULL);
- LIST_FOREACH(vip, &top->vi_child_head, vi_sibling)
- if (strlen(vip->vi_name) == namelen &&
- strncmp(name, vip->vi_name, namelen) == 0) {
- if (next_name != NULL)
- return(vimage_by_name(vip, next_name));
- else
- return(vip);
- }
- return(NULL);
-}
-
-static void
-vimage_relative_name(struct vimage *top, struct vimage *where,
- char *buffer, int bufflen)
-{
- int used = 1;
-
- if (where == top) {
- sprintf(buffer, ".");
- return;
- } else
- *buffer = 0;
-
- do {
- int namelen = strlen(where->vi_name);
-
- if (namelen + used + 1 >= bufflen)
- panic("buffer overflow");
-
- if (used > 1) {
- bcopy(buffer, &buffer[namelen + 1], used);
- buffer[namelen] = '.';
- used++;
- } else
- bcopy(buffer, &buffer[namelen], used);
- bcopy(where->vi_name, buffer, namelen);
- used += namelen;
- where = where->vi_parent;
- } while (where != top);
-}
-
-static struct vimage *
-vimage_get_next(struct vimage *top, struct vimage *where, int recurse)
-{
- struct vimage *next;
-
- if (recurse) {
- /* Try to go deeper in the hierarchy */
- next = LIST_FIRST(&where->vi_child_head);
- if (next != NULL)
- return(next);
- }
-
- do {
- /* Try to find next sibling */
- next = LIST_NEXT(where, vi_sibling);
- if (!recurse || next != NULL)
- return(next);
-
- /* Nothing left on this level, go one level up */
- where = where->vi_parent;
- } while (where != top->vi_parent);
-
- /* Nothing left to be visited, we are done */
- return(NULL);
-}
-
int
vi_td_ioctl(u_long cmd, struct vi_req *vi_req, struct thread *td)
{
@@ -273,11 +179,9 @@
if (vi_req->vi_api_cookie != VI_API_COOKIE)
return (EDOOFUS);
-#if 0
- error = priv_check(td, PRIV_ROOT);
+ error = priv_check(td, PRIV_REBOOT); /* XXX temp. priv abuse */
if (error)
return (error);
-#endif
vip_r = vimage_by_name(vip, vi_req->vi_name);
if (vip_r == NULL && !(vi_req->vi_req_action & VI_CREATE))
@@ -363,13 +267,109 @@
if (vip_r == NULL)
return (ENOMEM);
}
+ }
+
+ return (error);
+}
+
+int
+vi_child_of(struct vimage *parent, struct vimage *child)
+{
+
+ if (child == parent)
+ return (0);
+ for (; child; child = child->vi_parent)
+ if (child == parent)
+ return (1);
+ return (0);
+}
+
+static struct vimage *
+vimage_by_name(struct vimage *top, char *name)
+{
+ struct vimage *vip;
+ char *next_name;
+ int namelen;
+
+ next_name = strchr(name, '.');
+ if (next_name != NULL) {
+ namelen = next_name - name;
+ next_name++;
+ if (namelen == 0) {
+ if (strlen(next_name) == 0)
+ return(top); /* '.' == this vimage */
+ else
+ return(NULL);
+ }
+ } else
+ namelen = strlen(name);
+ if (namelen == 0)
+ return(NULL);
+ LIST_FOREACH(vip, &top->vi_child_head, vi_sibling)
+ if (strlen(vip->vi_name) == namelen &&
+ strncmp(name, vip->vi_name, namelen) == 0) {
+ if (next_name != NULL)
+ return(vimage_by_name(vip, next_name));
+ else
+ return(vip);
+ }
+ return(NULL);
+}
- /* XXX What the hell is this doing here? */
- if (vip == vip_r && !IS_DEFAULT_VIMAGE(vip))
- return (EPERM);
+static void
+vimage_relative_name(struct vimage *top, struct vimage *where,
+ char *buffer, int bufflen)
+{
+ int used = 1;
+
+ if (where == top) {
+ sprintf(buffer, ".");
+ return;
+ } else
+ *buffer = 0;
+
+ do {
+ int namelen = strlen(where->vi_name);
+
+ if (namelen + used + 1 >= bufflen)
+ panic("buffer overflow");
+
+ if (used > 1) {
+ bcopy(buffer, &buffer[namelen + 1], used);
+ buffer[namelen] = '.';
+ used++;
+ } else
+ bcopy(buffer, &buffer[namelen], used);
+ bcopy(where->vi_name, buffer, namelen);
+ used += namelen;
+ where = where->vi_parent;
+ } while (where != top);
+}
+
+static struct vimage *
+vimage_get_next(struct vimage *top, struct vimage *where, int recurse)
+{
+ struct vimage *next;
+
+ if (recurse) {
+ /* Try to go deeper in the hierarchy */
+ next = LIST_FIRST(&where->vi_child_head);
+ if (next != NULL)
+ return(next);
}
- return (error);
+ do {
+ /* Try to find next sibling */
+ next = LIST_NEXT(where, vi_sibling);
+ if (!recurse || next != NULL)
+ return(next);
+
+ /* Nothing left on this level, go one level up */
+ where = where->vi_parent;
+ } while (where != top->vi_parent);
+
+ /* Nothing left to be visited, we are done */
+ return(NULL);
}
#endif /* VIMAGE */ /* User interface block */
@@ -654,9 +654,9 @@
vnet_mod_constructor(vml);
CURVNET_RESTORE();
- VNET_LIST_LOCK();
+ VNET_LIST_WLOCK();
LIST_INSERT_HEAD(&vnet_head, vnet, vnet_le);
- VNET_LIST_UNLOCK();
+ VNET_LIST_WUNLOCK();
/* XXX locking */
LIST_INSERT_HEAD(&vprocg_head, vprocg, vprocg_le);
More information about the p4-projects
mailing list