Date: Wed, 23 Oct 2013 18:32:25 +0000 (UTC) From: Will Andrews <will@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r257000 - projects/vps/sys/vps Message-ID: <201310231832.r9NIWP0H093494@svn.freebsd.org>
index | next in thread | raw e-mail
Author: will Date: Wed Oct 23 18:32:25 2013 New Revision: 257000 URL: http://svnweb.freebsd.org/changeset/base/257000 Log: Sync with svn.7he.at/vps/trunk r195. r195 | klaus | 2013-07-29 06:35:25 -0600 (Mon, 29 Jul 2013) | 3 lines Added support for dumping fsid+fileid instead of path for vnodes. Submitted by: Klaus P. Ohrhallinger <k@7he.at> Modified: projects/vps/sys/vps/vps_libdump.h projects/vps/sys/vps/vps_restore.c projects/vps/sys/vps/vps_snapst.c Modified: projects/vps/sys/vps/vps_libdump.h ============================================================================== --- projects/vps/sys/vps/vps_libdump.h Wed Oct 23 18:22:27 2013 (r256999) +++ projects/vps/sys/vps/vps_libdump.h Wed Oct 23 18:32:25 2013 (r257000) @@ -127,11 +127,12 @@ void vps_libdump_printheader(struct vps_ #define VPS_DUMPOBJT_KNOTE 81 #define VPS_DUMPOBJT_KEVENT 82 #define VPS_DUMPOBJT_UMTX 90 +#define VPS_DUMPOBJT_FILE_INODENUM 95 #define VPS_DUMPOBJT_PRISON 100 #define VPS_DUMPOBJT_UCRED 120 #define VPS_DUMPH_MAGIC 0xc0debabe -#define VPS_DUMPH_VERSION 0x20130719 +#define VPS_DUMPH_VERSION 0x20130729 #define VPS_DUMPH_MSB 12 #define VPS_DUMPH_LSB 21 #define VPS_DUMPH_32BIT 32 @@ -639,6 +640,12 @@ struct vps_dump_filepath { char fp_path[0]; /* always padded to 64 bit alignment */ }; +struct vps_dump_fileinodenum { + uint64 fsid; + sint32 fileid; + uint32 _pad0; +}; + struct vps_dump_pts { sint32 pt_index; sint32 pt_pgrp_id; Modified: projects/vps/sys/vps/vps_restore.c ============================================================================== --- projects/vps/sys/vps/vps_restore.c Wed Oct 23 18:22:27 2013 (r256999) +++ projects/vps/sys/vps/vps_restore.c Wed Oct 23 18:32:25 2013 (r257000) @@ -2153,6 +2153,94 @@ vps_restore_pathtovnode(struct vps_snaps return (0); } +/* EXPERIMENTAL - nfs doesn't support vfs_vget() :-( */ +VPSFUNC +static int +vps_restore_inodenumtovnode(struct vps_snapst_ctx *ctx, struct vps *vps, + struct vnode **vnp) +{ + struct vps_dump_fileinodenum *vdfi; + struct vps_dumpobj *o1; + struct mount *mp; + struct vnode *vp; + char *vpsroot; + char *mnton; + int len; + int error; + + o1 = vdo_next(ctx); + + if (o1->type != VPS_DUMPOBJT_FILE_INODENUM) + return (EINVAL); + + vdfi = (struct vps_dump_fileinodenum *)o1->data; + + DBGR("%s: fsid=%lu fileid=%d\n", __func__, vdfi->fsid, vdfi->fileid); + + DBGR("%s: vps's rootpath=[%s] vnode=%p\n", + __func__, vps->_rootpath, vps->_rootvnode); + + vpsroot = strdup(vps->_rootpath, M_TEMP); + if (vpsroot[strlen(vpsroot) - 1] == '/') + vpsroot[strlen(vpsroot) - 1] = '\0'; + len = strlen(vpsroot); + + mtx_lock(&mountlist_mtx); + TAILQ_FOREACH(mp, &mountlist, mnt_list) { + mnton = mp->mnt_stat.f_mntonname; + if (!(strncmp(vpsroot, mnton, len) == 0 && + (mnton[len] == '\0' || mnton[len] == '/'))) + continue; + + if (mp->mnt_stat.f_fsid.val[0] == vdfi->fsid) + break; + } + mtx_unlock(&mountlist_mtx); + + free(vpsroot, M_TEMP); + + if (mp == NULL) { + ERRMSG(ctx, "%s: no mount found for fsid [%16x]\n", + __func__, vdfi->fsid); + return (ENOENT); + } else + DBGR("%s: got mount=%p for fsid\n", __func__, mp); + + error = VFS_VGET(mp, vdfi->fileid, LK_SHARED | LK_RETRY, &vp); + if (error != 0) { + ERRMSG(ctx, "%s: VFS_VGET() error=%d\n", + __func__, error); + return (error); + } + + *vnp = vp; + + vref(vp); + VOP_UNLOCK(vp, 0); + + return (0); +} + +VPSFUNC +static int +vps_restore_vnode(struct vps_snapst_ctx *ctx, struct vps *vps, + struct vnode **vnp) +{ + int error; + + if (vdo_typeofnext(ctx) == VPS_DUMPOBJT_FILE_INODENUM) + error = vps_restore_inodenumtovnode(ctx, vps, vnp); + else if (vdo_typeofnext(ctx) == VPS_DUMPOBJT_FILE_PATH) + error = vps_restore_pathtovnode(ctx, vps, vnp); + else { + ERRMSG(ctx, "%s: vdo_typeofnext(ctx)=%d\n", + __func__, vdo_typeofnext(ctx)); + return (EINVAL); + } + + return (error); +} + VPSFUNC static int vps_restore_file_vnode(struct vps_snapst_ctx *ctx, struct vps *vps, @@ -2650,17 +2738,17 @@ vps_restore_fdset(struct vps_snapst_ctx cfd = curthread->td_proc->p_fd; if (vdfd->fd_have_cdir != 0) { - if ((error = vps_restore_pathtovnode(ctx, vps, + if ((error = vps_restore_vnode(ctx, vps, &p->p_fd->fd_cdir))) return (error); } if (vdfd->fd_have_rdir != 0) { - if ((error = vps_restore_pathtovnode(ctx, vps, + if ((error = vps_restore_vnode(ctx, vps, &p->p_fd->fd_rdir))) return (error); } if (vdfd->fd_have_jdir != 0) { - if ((error = vps_restore_pathtovnode(ctx, vps, + if ((error = vps_restore_vnode(ctx, vps, &p->p_fd->fd_jdir))) return (error); } @@ -3589,7 +3677,7 @@ vps_restore_proc_one(struct vps_snapst_c /* ktrace */ if (vdp->p_have_tracevp) { - if ((error = vps_restore_pathtovnode(ctx, vps, + if ((error = vps_restore_vnode(ctx, vps, &np->p_tracevp))) goto out; /* @@ -3608,7 +3696,7 @@ vps_restore_proc_one(struct vps_snapst_c /* textvp */ if (vdp->p_have_textvp) { - if ((error = vps_restore_pathtovnode(ctx, vps, + if ((error = vps_restore_vnode(ctx, vps, &np->p_textvp))) goto out; DBGR("%s: p_textvp: path [...] got vnode %p\n", @@ -4387,7 +4475,7 @@ vps_restore_prison_one(struct vps_snapst */ strlcpy(npr->pr_path, vdpr->pr_path, sizeof(vdpr->pr_path)); - if ((error = vps_restore_pathtovnode(ctx, vps, + if ((error = vps_restore_vnode(ctx, vps, &npr->pr_root))) return (error); Modified: projects/vps/sys/vps/vps_snapst.c ============================================================================== --- projects/vps/sys/vps/vps_snapst.c Wed Oct 23 18:22:27 2013 (r256999) +++ projects/vps/sys/vps/vps_snapst.c Wed Oct 23 18:32:25 2013 (r257000) @@ -652,7 +652,7 @@ vps_snapshot(struct vps_dev_ctx *dev_ctx VPSFUNC static int vps_snapshot_vnodepath(struct vps_snapst_ctx *ctx, struct vps *vps, - struct vnode *vp, int howalloc) + struct vnode *vp, int howalloc) { struct vps_dumpobj *o1; struct vps_dump_filepath *vdfp; @@ -667,10 +667,11 @@ vps_snapshot_vnodepath(struct vps_snapst if (vp == NULL) return (0); - vref(vp); howalloc &= (M_WAITOK|M_NOWAIT); if (howalloc == 0) return (EINVAL); + + vref(vp); buf = malloc(MAXPATHLEN, M_TEMP, howalloc|M_ZERO); if (buf == NULL) { vrele(vp); @@ -734,6 +735,91 @@ vps_snapshot_vnodepath(struct vps_snapst return (0); } +VPSFUNC +static int +vps_snapshot_vnodeinodenum(struct vps_snapst_ctx *ctx, struct vps *vps, + struct vnode *vp, int howalloc) +{ + struct vps_dump_fileinodenum *vdfi; + struct vps_dumpobj *o1; + struct vattr vattr; + int error; + + if (vp == NULL) + return (0); + + howalloc &= (M_WAITOK|M_NOWAIT); + if (howalloc == 0) + return (EINVAL); + + vref(vp); + vn_lock(vp, LK_SHARED | LK_RETRY); + error = VOP_GETATTR(vp, &vattr, curthread->td_ucred); + VOP_UNLOCK(vp, 0); + + if (error != 0) { + DBGS("%s: vnode=%p VOP_GETATTR(): error=%d\n", + __func__, vp, error); + vrele(vp); + return (error); + } + + DBGS("%s: vnode=%p fsid=%u fileid=%ld error=%d\n", + __func__, vp, vattr.va_fsid, vattr.va_fileid, error); + + o1 = vdo_create(ctx, VPS_DUMPOBJT_FILE_INODENUM, howalloc); + if (o1 == NULL) { + vrele(vp); + return (ENOMEM); + } + if ((vdfi = vdo_space(ctx, sizeof(*vdfi), howalloc)) == NULL) { + vdo_discard(ctx, o1); + vrele(vp); + return (ENOMEM); + } + + vdfi->fsid = vattr.va_fsid; + vdfi->fileid = vattr.va_fileid; + + vdo_close(ctx); + vrele(vp); + + return (0); +} + +/* + * EXPERIMENTAL: + * Depending of kind of filesystem choose whether we snapshot + * a path to the vnode (unreliable and sometimes slow) or + * the inode number (aka file id). + */ +VPSFUNC +static int +vps_snapshot_vnode(struct vps_snapst_ctx *ctx, struct vps *vps, + struct vnode *vp, int howalloc) +{ + int error; + + if (vp == NULL) + return (0); + + vref(vp); + + /* + nfs doesn't support vfs_vget() + if (!strcmp(vp->v_tag, "newnfs")) { + */ + if (0) { + error = vps_snapshot_vnodeinodenum(ctx, vps, vp, howalloc); + } else { + error = vps_snapshot_vnodepath(ctx, vps, vp, howalloc); + } + + vrele(vp); + + return (error); +} + /* * Pseudo teletype device. */ @@ -1602,9 +1688,9 @@ vps_snapshot_prison_one(struct vps_snaps pr->pr_ref++; prison_unlock(pr); - if ((error = vps_snapshot_vnodepath(ctx, vps, rootvp, M_WAITOK))) { + if ((error = vps_snapshot_vnode(ctx, vps, rootvp, M_WAITOK))) { vrele(rootvp); - DBGS("%s: vps_snapshot_vnodepath: %d\n", __func__, error); + DBGS("%s: vps_snapshot_vnode: %d\n", __func__, error); goto out; } vrele(rootvp); @@ -1726,7 +1812,7 @@ vps_snapshot_proc(struct vps_snapst_ctx sizeof(sess->s_login)); if (sess->s_ttyvp) - vps_snapshot_vnodepath(ctx, vps, + vps_snapshot_vnode(ctx, vps, sess->s_ttyvp, M_WAITOK); vdo_close(ctx); @@ -2129,7 +2215,7 @@ vps_snapshot_socket_unix(struct vps_snap if (un_pcb->unp_vnode != NULL) { vdunpcb->unp_have_vnode = 1; /* - if ((error = vps_snapshot_vnodepath(ctx, vps, + if ((error = vps_snapshot_vnode(ctx, vps, un_pcb->unp_vnode, M_NOWAIT))) goto drop; */ @@ -2521,13 +2607,13 @@ vps_snapshot_fdset(struct vps_snapst_ctx vdo_space(ctx, sizeof(vdfd->fd_entries[0]) * vdfd->fd_nfiles, M_WAITOK); - if ((error = vps_snapshot_vnodepath(ctx, vps, fdp->fd_cdir, + if ((error = vps_snapshot_vnode(ctx, vps, fdp->fd_cdir, M_WAITOK))) goto out; - if ((error = vps_snapshot_vnodepath(ctx, vps, fdp->fd_rdir, + if ((error = vps_snapshot_vnode(ctx, vps, fdp->fd_rdir, M_WAITOK))) goto out; - if ((error = vps_snapshot_vnodepath(ctx, vps, fdp->fd_jdir, + if ((error = vps_snapshot_vnode(ctx, vps, fdp->fd_jdir, M_WAITOK))) goto out; @@ -2575,9 +2661,9 @@ vps_snapshot_fdset(struct vps_snapst_ctx do refer to a vnode ? */ if (fp->f_vnode == NULL) break; - if ((error = vps_snapshot_vnodepath(ctx, vps, + if ((error = vps_snapshot_vnode(ctx, vps, fp->f_vnode, M_WAITOK))) { - ERRMSG(ctx, "%s: vps_snapshot_vnodepath(): " + ERRMSG(ctx, "%s: vps_snapshot_vnode(): " "%d\n", __func__, error); goto out; } @@ -2975,7 +3061,7 @@ vps_snapshot_vmobject(struct vps_snapst_ goto out; } #endif - error = vps_snapshot_vnodepath(ctx, vps, vp, + error = vps_snapshot_vnode(ctx, vps, vp, M_WAITOK); if (error != 0) { vdo_discard(ctx, o1); @@ -3438,7 +3524,7 @@ vps_snapshot_proc_one(struct vps_snapst_ /* ktrace */ if (p->p_tracevp != NULL) { - if ((error = vps_snapshot_vnodepath(ctx, vps, p->p_tracevp, + if ((error = vps_snapshot_vnode(ctx, vps, p->p_tracevp, M_WAITOK))) goto out; vdp->p_have_tracevp = 1; @@ -3446,7 +3532,7 @@ vps_snapshot_proc_one(struct vps_snapst_ /* Executable vnode. */ if (p->p_textvp != NULL) { - if ((error = vps_snapshot_vnodepath(ctx, vps, p->p_textvp, + if ((error = vps_snapshot_vnode(ctx, vps, p->p_textvp, M_WAITOK))) goto out; vdp->p_have_textvp = 1;help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201310231832.r9NIWP0H093494>
