PERFORCE change 178952 for review
Efstratios Karatzas
gpf at FreeBSD.org
Sat May 29 11:23:42 UTC 2010
http://p4web.freebsd.org/@@178952?ac=10
Change 178952 by gpf at gpf_desktop on 2010/05/29 11:23:28
- added calls to vn_fullpath_nocache() when vn_fullpath_global()
fails in nfs server code for the following operations:
getattr, setattr, lookup, access, readlink, read, write, create,
mknod, remove, rename
- few minor changes in nfs server code
Affected files ...
.. //depot/projects/soc2010/gpf_audit/freebsd/src/sys/nfsserver/nfs_serv.c#10 edit
Differences ...
==== //depot/projects/soc2010/gpf_audit/freebsd/src/sys/nfsserver/nfs_serv.c#10 (text+ko) ====
@@ -282,6 +282,18 @@
AUDIT_ARG_UPATH1(td, fullpath);
free(freepath, M_TEMP);
}
+ /* if our cache fails us */
+ else if (fhp != NULL && AUDIT_vp->v_mount != NULL) {
+ uint64_t parent_hint;
+ /* get the hint stored inside the file handle */
+ VFS_FHHINT(AUDIT_vp->v_mount, &fhp->fh_fid, &parent_hint);
+ vn_fullpath_nocache(AUDIT_vp, &fullpath, &freepath,
+ parent_hint, PARENTHINT | WANTNAME);
+ if (freepath != NULL) {
+ AUDIT_ARG_UPATH1(td, fullpath);
+ free(freepath, M_TEMP);
+ }
+ }
}
}
@@ -357,6 +369,18 @@
AUDIT_ARG_UPATH1(td, fullpath);
free(freepath, M_TEMP);
}
+ /* if our cache fails us */
+ else if (fhp != NULL && AUDIT_vp->v_mount != NULL) {
+ uint64_t parent_hint;
+ /* get the hint stored inside the file handle */
+ VFS_FHHINT(AUDIT_vp->v_mount, &fhp->fh_fid, &parent_hint);
+ vn_fullpath_nocache(AUDIT_vp, &fullpath, &freepath,
+ parent_hint, PARENTHINT | WANTNAME);
+ if (freepath != NULL) {
+ AUDIT_ARG_UPATH1(td, fullpath);
+ free(freepath, M_TEMP);
+ }
+ }
}
}
@@ -537,6 +561,18 @@
AUDIT_ARG_UPATH1(td, fullpath);
free(freepath, M_TEMP);
}
+ /* if our cache fails us */
+ else if (fhp != NULL && AUDIT_vp->v_mount != NULL) {
+ uint64_t parent_hint;
+ /* get the hint stored inside the file handle */
+ VFS_FHHINT(AUDIT_vp->v_mount, &fhp->fh_fid, &parent_hint);
+ vn_fullpath_nocache(AUDIT_vp, &fullpath, &freepath,
+ parent_hint, PARENTHINT | WANTNAME);
+ if (freepath != NULL) {
+ AUDIT_ARG_UPATH1(td, fullpath);
+ free(freepath, M_TEMP);
+ }
+ }
}
}
@@ -745,6 +781,18 @@
AUDIT_ARG_UPATH1(td, fullpath);
free(freepath, M_TEMP);
}
+ /* if our cache fails us */
+ else if (fhp != NULL && AUDIT_vp->v_mount != NULL) {
+ uint64_t parent_hint;
+ /* get the hint stored inside the file handle */
+ VFS_FHHINT(AUDIT_vp->v_mount, &fhp->fh_fid, &parent_hint);
+ vn_fullpath_nocache(AUDIT_vp, &fullpath, &freepath,
+ parent_hint, PARENTHINT | WANTNAME);
+ if (freepath != NULL) {
+ AUDIT_ARG_UPATH1(td, fullpath);
+ free(freepath, M_TEMP);
+ }
+ }
}
}
@@ -874,6 +922,18 @@
AUDIT_ARG_UPATH1(td, fullpath);
free(freepath, M_TEMP);
}
+ /* if our cache fails us */
+ else if (fhp != NULL && link_vp->v_mount != NULL) {
+ uint64_t parent_hint;
+ /* get the hint stored inside the file handle */
+ VFS_FHHINT(link_vp->v_mount, &fhp->fh_fid, &parent_hint);
+ vn_fullpath_nocache(link_vp, &fullpath, &freepath,
+ parent_hint, PARENTHINT | WANTNAME);
+ if (freepath != NULL) {
+ AUDIT_ARG_UPATH1(td, fullpath);
+ free(freepath, M_TEMP);
+ }
+ }
}
}
@@ -1145,6 +1205,18 @@
AUDIT_ARG_UPATH1(td, fullpath);
free(freepath, M_TEMP);
}
+ /* if our cache fails us */
+ else if (fhp != NULL && new_vp->v_mount != NULL) {
+ uint64_t parent_hint;
+ /* get the hint stored inside the file handle */
+ VFS_FHHINT(new_vp->v_mount, &fhp->fh_fid, &parent_hint);
+ vn_fullpath_nocache(new_vp, &fullpath, &freepath,
+ parent_hint, PARENTHINT | WANTNAME);
+ if (freepath != NULL) {
+ AUDIT_ARG_UPATH1(td, fullpath);
+ free(freepath, M_TEMP);
+ }
+ }
}
}
@@ -1370,21 +1442,7 @@
vn_finished_write(mntp);
VFS_UNLOCK_GIANT(vfslocked);
- /* XXX AUDIT */
-
- /*
- * another way we could go about re-obtaining the vp from the file handle.
- * right now, I think i like the new_vp method better
- */
- /*
- if (vp == NULL) {
- tvfslocked = 0;
- error = nfsrv_fhtovp(fhp, 0, &vp, &tvfslocked,
- nfsd, slp, nam, &rdonly, TRUE);
- if (error)
- vp = NULL;
- }
- */
+ /* XXX AUDIT */
if (AUDITING_TD(curthread)) {
if (new_vp != NULL) {
struct thread *td = curthread;
@@ -1399,20 +1457,16 @@
free(freepath, M_TEMP);
}
/* if our cache fails us */
- else if (fhp != NULL) {
+ else if (fhp != NULL && new_vp->v_mount != NULL) {
uint64_t parent_hint;
- printf("going for hint\n");
/* get the hint stored inside the file handle */
- VFS_FHHINT(mntp, &(fhp->fh_fid), &parent_hint);
- printf("got hint, going to cache\n");
+ VFS_FHHINT(new_vp->v_mount, &fhp->fh_fid, &parent_hint);
vn_fullpath_nocache(new_vp, &fullpath, &freepath,
parent_hint, PARENTHINT | WANTNAME);
- printf("got cache %p\n", freepath);
if (freepath != NULL) {
AUDIT_ARG_UPATH1(td, fullpath);
free(freepath, M_TEMP);
}
- printf("all done!\n");
}
}
}
@@ -1725,6 +1779,10 @@
AUDIT_ARG_VNODE1(nd.ni_vp);
+ /* save the name of the new file in case everything fails */
+ if (nd.ni_cnd.cn_pnbuf != NULL)
+ strlcpy(path, nd.ni_cnd.cn_pnbuf, sizeof(path));
+
freepath = NULL;
vn_fullpath_global(td, nd.ni_vp, &fullpath, &freepath);
if (freepath != NULL) {
@@ -1738,9 +1796,17 @@
snprintf(path, sizeof(path), "%s/%s", fullpath, nd.ni_cnd.cn_pnbuf);
free(freepath, M_TEMP);
}
- /* last resort: just save the name of the new file */
- else {
- strlcpy(path, nd.ni_cnd.cn_pnbuf, sizeof(path));
+ /* if our cache fails us */
+ else if (fhp != NULL && nd.ni_vp->v_mount != NULL) {
+ uint64_t parent_hint;
+ /* get the hint stored inside the file handle */
+ VFS_FHHINT(nd.ni_vp->v_mount, &fhp->fh_fid, &parent_hint);
+ vn_fullpath_nocache(nd.ni_vp, &fullpath, &freepath,
+ parent_hint, PARENTHINT | WANTNAME);
+ if (freepath != NULL) {
+ strlcpy(path, fullpath, sizeof(path));
+ free(freepath, M_TEMP);
+ }
}
}
@@ -1938,45 +2004,12 @@
nfsm_srvwcc_data(dirfor_ret, &dirfor, diraft_ret, &diraft);
}
vn_finished_write(mp);
- VFS_UNLOCK_GIANT(vfslocked);
-
- /* XXX AUDIT */
- if (AUDITING_TD(curthread)) {
- if (AUDIT_vp != NULL) {
- AUDIT_ARG_VNODE1(AUDIT_vp);
- }
+ VFS_UNLOCK_GIANT(vfslocked);
- if (AUDIT_dvp != NULL) {
- char path[PATH_MAX];
- struct thread *td = curthread;
- char *fullpath, *freepath;
-
- freepath = NULL;
- if (AUDIT_vp != NULL)
- vn_fullpath_global(td, AUDIT_vp, &fullpath, &freepath);
- if (freepath != NULL) {
- strlcpy(path, fullpath, sizeof(path));
- free(freepath, M_TEMP);
- }
- /* if we fail to acquire a path from the new vnode, use the directory vnode instead */
- else if (nd.ni_cnd.cn_pnbuf != NULL) {
-
- vn_fullpath_global(td, AUDIT_dvp, &fullpath, &freepath);
- if (freepath != NULL) {
- snprintf(path, sizeof(path), "%s/%s", fullpath, nd.ni_cnd.cn_pnbuf);
- free(freepath, M_TEMP);
- }
- /* last resort: just save the name of the new file */
- else {
- strlcpy(path, nd.ni_cnd.cn_pnbuf, sizeof(path));
- }
- }
-
- AUDIT_ARG_UPATH1(td, path);
- }
- }
-
- return (0);
+ /* XXX audit */
+ /* return (0); */
+ error = 0;
+ goto audit;
nfsmout:
if (nd.ni_dvp) {
if (nd.ni_dvp == nd.ni_vp)
@@ -1994,39 +2027,52 @@
vn_finished_write(mp);
VFS_UNLOCK_GIANT(vfslocked);
+audit:
/* XXX AUDIT */
if (AUDITING_TD(curthread)) {
+ char path[PATH_MAX];
+ struct thread *td = curthread;
+ char *fullpath, *freepath;
+
+ /* save the name of the new node in case everything fails */
+ if (nd.ni_cnd.cn_pnbuf != NULL)
+ strlcpy(path, nd.ni_cnd.cn_pnbuf, sizeof(path));
+
+ freepath = NULL;
if (AUDIT_vp != NULL) {
- AUDIT_ARG_VNODE1(AUDIT_vp);
- }
-
- if (AUDIT_dvp != NULL) {
- char path[PATH_MAX];
- struct thread *td = curthread;
- char *fullpath, *freepath;
-
- freepath = NULL;
+ AUDIT_ARG_VNODE1(AUDIT_vp);
if (AUDIT_vp != NULL)
vn_fullpath_global(td, AUDIT_vp, &fullpath, &freepath);
+
if (freepath != NULL) {
strlcpy(path, fullpath, sizeof(path));
free(freepath, M_TEMP);
}
- /* if we fail to acquire a path from the new vnode, use the directory vnode instead */
- else if (nd.ni_cnd.cn_pnbuf != NULL) {
+ /* if our cache fails us */
+ else if (fhp != NULL && AUDIT_vp->v_mount != NULL) {
+ uint64_t parent_hint;
+ /* get the hint stored inside the file handle */
+ VFS_FHHINT(AUDIT_vp->v_mount, &fhp->fh_fid, &parent_hint);
+ vn_fullpath_nocache(AUDIT_vp, &fullpath, &freepath,
+ parent_hint, PARENTHINT | WANTNAME);
+ if (freepath != NULL) {
+ strlcpy(path, fullpath, sizeof(path));
+ free(freepath, M_TEMP);
+ }
+ }
+ }
+ /* if we haven't acquired a path, try to grab the parent directory path instead */
+ if (freepath == NULL && AUDIT_dvp != NULL) {
+ if (nd.ni_cnd.cn_pnbuf != NULL) {
vn_fullpath_global(td, AUDIT_dvp, &fullpath, &freepath);
if (freepath != NULL) {
snprintf(path, sizeof(path), "%s/%s", fullpath, nd.ni_cnd.cn_pnbuf);
free(freepath, M_TEMP);
}
- /* last resort: just save the name of the new file */
- else {
- strlcpy(path, nd.ni_cnd.cn_pnbuf, sizeof(path));
- }
}
+ }
- AUDIT_ARG_UPATH1(td, path);
- }
+ AUDIT_ARG_UPATH1(td, path);
}
return (error);
@@ -2153,6 +2199,9 @@
char *fullpath, *freepath;
if (parent_dvp != NULL && nd.ni_cnd.cn_pnbuf != NULL) {
+ /* save the name of the deleted file in case everything fails */
+ strlcpy(path, nd.ni_cnd.cn_pnbuf, sizeof(path));
+
/* use the directory vnode to acquire the old path */
freepath = NULL;
vn_fullpath_global(td, parent_dvp, &fullpath, &freepath);
@@ -2160,10 +2209,16 @@
snprintf(path, sizeof(path), "%s/%s", fullpath, nd.ni_cnd.cn_pnbuf);
free(freepath, M_TEMP);
}
- /* last resort: just save the name of the deleted dir */
- else {
- strlcpy(path, nd.ni_cnd.cn_pnbuf, sizeof(path));
+ /* if our cache fails us */
+ else if (fhp != NULL && parent_dvp->v_mount != NULL) {
+ vn_fullpath_nocache(parent_dvp, &fullpath, &freepath,
+ 0, WANTNAME);
+ if (freepath != NULL) {
+ snprintf(path, sizeof(path), "%s/%s", fullpath, nd.ni_cnd.cn_pnbuf);
+ free(freepath, M_TEMP);
+ }
}
+
AUDIT_ARG_UPATH1(td, path);
}
}
@@ -2415,6 +2470,9 @@
char *fullpath, *freepath;
if (from_dvp != NULL && fromnd.ni_cnd.cn_pnbuf != NULL) {
+ /* save the old name of old file in case everything fails */
+ strlcpy(path, fromnd.ni_cnd.cn_pnbuf, sizeof(path));
+
/* use the directory vnode to acquire the old path */
freepath = NULL;
vn_fullpath_global(td, from_dvp, &fullpath, &freepath);
@@ -2422,18 +2480,26 @@
snprintf(path, sizeof(path), "%s/%s", fullpath, fromnd.ni_cnd.cn_pnbuf);
free(freepath, M_TEMP);
}
- /* last resort: just save the name of the old file */
+ /* if our cache fails us */
else {
- strlcpy(path, fromnd.ni_cnd.cn_pnbuf, sizeof(path));
+ vn_fullpath_nocache(from_dvp, &fullpath, &freepath,
+ 0, WANTNAME);
+ if (freepath != NULL) {
+ snprintf(path, sizeof(path), "%s/%s", fullpath, fromnd.ni_cnd.cn_pnbuf);
+ free(freepath, M_TEMP);
+ }
}
AUDIT_ARG_UPATH1(td, path);
}
-
+
if (vp != NULL) {
AUDIT_ARG_VNODE1(vp);
}
-
+
if (to_dvp != NULL && tond.ni_cnd.cn_pnbuf != NULL) {
+ /* save the new name of the file in case everything fails */
+ strlcpy(path, tond.ni_cnd.cn_pnbuf, sizeof(path));
+
/* use the directory vnode to acquire the new path */
freepath = NULL;
vn_fullpath_global(td, to_dvp, &fullpath, &freepath);
@@ -2441,9 +2507,14 @@
snprintf(path, sizeof(path), "%s/%s", fullpath, tond.ni_cnd.cn_pnbuf);
free(freepath, M_TEMP);
}
- /* last resort: just save the name of the new file */
+ /* if our cache fails us */
else {
- strlcpy(path, tond.ni_cnd.cn_pnbuf, sizeof(path));
+ vn_fullpath_nocache(to_dvp, &fullpath, &freepath,
+ 0, WANTNAME);
+ if (freepath != NULL) {
+ snprintf(path, sizeof(path), "%s/%s", fullpath, tond.ni_cnd.cn_pnbuf);
+ free(freepath, M_TEMP);
+ }
}
AUDIT_ARG_UPATH2(td, path);
}
More information about the p4-projects
mailing list