PERFORCE change 125099 for review
Marko Zec
zec at FreeBSD.org
Mon Aug 13 00:02:37 PDT 2007
http://perforce.freebsd.org/chv.cgi?CH=125099
Change 125099 by zec at zec_tpx32 on 2007/08/13 07:01:54
A hack to resolve character "@" to vimage name when following
symbolic links. This is controlled on per-vimage basis via the
new vfs.morphing_symlinks sysctl and is off by default. The
primary use of this will be in IMUNES network topology emulator
to allow running of multiple instances of unmodified applications
with some hard coded filesystem paths, most notably quagga.
While here, slightly change the format of warning messages
displayed if / when vnet "stacking" occurs.
Affected files ...
.. //depot/projects/vimage/src/sys/kern/vfs_lookup.c#6 edit
.. //depot/projects/vimage/src/sys/sys/vimage.h#33 edit
Differences ...
==== //depot/projects/vimage/src/sys/kern/vfs_lookup.c#6 (text+ko) ====
@@ -40,6 +40,7 @@
#include "opt_ktrace.h"
#include "opt_mac.h"
#include "opt_vfs.h"
+#include "opt_vimage.h"
#include <sys/param.h>
#include <sys/systm.h>
@@ -53,6 +54,7 @@
#include <sys/proc.h>
#include <sys/syscallsubr.h>
#include <sys/sysctl.h>
+#include <sys/vimage.h>
#ifdef KTRACE
#include <sys/ktrace.h>
#endif
@@ -65,6 +67,15 @@
#define NAMEI_DIAGNOSTIC 1
#undef NAMEI_DIAGNOSTIC
+#ifdef VIMAGE
+#define IMUNES_SYMLINK_HACK
+#endif
+
+#ifdef IMUNES_SYMLINK_HACK
+SYSCTL_V_INT(V_PROCG, vprocg, _vfs, OID_AUTO, morphing_symlinks, CTLFLAG_RW,
+ morphing_symlinks, 0, "Resolve @ to vimage name in symlinks");
+#endif
+
/*
* Allocation zone for namei
*/
@@ -129,6 +140,9 @@
struct thread *td = cnp->cn_thread;
struct proc *p = td->td_proc;
int vfslocked;
+#ifdef IMUNES_SYMLINK_HACK
+ INIT_VPROCG(td->td_ucred->cr_vimage->v_procg);
+#endif
KASSERT((cnp->cn_flags & MPSAFE) != 0 || mtx_owned(&Giant) != 0,
("NOT MPSAFE and Giant not held"));
@@ -284,6 +298,26 @@
error = ENOENT;
break;
}
+#ifdef IMUNES_SYMLINK_HACK
+ if (V_morphing_symlinks) {
+ char *sp = strchr(cp, '@');
+ int vnamelen = strlen(td->td_ucred->cr_vimage->vi_name);
+
+ if (sp) {
+ if (vnamelen >= auio.uio_resid) {
+ if (ndp->ni_pathlen > 1)
+ uma_zfree(namei_zone, cp);
+ error = ENAMETOOLONG;
+ break;
+ }
+ bcopy(sp + 1, sp + vnamelen,
+ vnamelen - (sp - cp));
+ bcopy(td->td_ucred->cr_vimage->vi_name, sp,
+ vnamelen);
+ linklen += (vnamelen - 1);
+ }
+ }
+#endif /* IMUNES_SYMLINK_HACK */
if (linklen + ndp->ni_pathlen >= MAXPATHLEN) {
if (ndp->ni_pathlen > 1)
uma_zfree(namei_zone, cp);
==== //depot/projects/vimage/src/sys/sys/vimage.h#33 (text+ko) ====
@@ -197,9 +197,9 @@
#define CURVNET_SET_VERBOSE(arg) \
CURVNET_SET_QUIET(arg) \
if (saved_vnet) \
- printf("curvnet_set(%p) in %s() on cpu %d, prev %s(%p)\n", \
+ printf("curvnet_set(%p) in %s() on cpu %d, prev %p in %s()\n", \
curvnet, curthread->td_vnet_lpush, curcpu, \
- saved_vnet_lpush, saved_vnet);
+ saved_vnet, saved_vnet_lpush);
#define CURVNET_SET(arg) CURVNET_SET_VERBOSE(arg)
@@ -291,6 +291,7 @@
#define V_cp_time VPROCG(cp_time)
#define V_hostname VPROCG(hostname)
#define V_domainname VPROCG(domainname)
+#define V_morphing_symlinks VPROCG(morphing_symlinks)
#ifdef VIMAGE
void vnet_mod_register(const struct vnet_modinfo *);
@@ -355,6 +356,8 @@
char _hostname[MAXHOSTNAMELEN];
char _domainname[MAXHOSTNAMELEN];
+ int _morphing_symlinks;
+
#if 0
struct loadavg averunnable; /* from kern/kern_synch.c */
int nrun;
@@ -374,9 +377,6 @@
struct timeval boottime;
long boottdelta_sec;
- int hostnamelen;
- int domainnamelen;
-
char chroot[MAXPATHLEN]; /* assigned/inherited from parent */
int big_brother; /* manage procs in all child vprocgs */
More information about the p4-projects
mailing list