Author: mjg
Date: Mon Apr 27 13:54:00 2020
New Revision: 360374
URL: https://svnweb.freebsd.org/changeset/base/360374

Log:
  pwd: unbreak repeated calls to set_rootvnode
  
  Prior to the change the once set pointer would never be updated.
  
  Unbreaks reboot -r.
  
  Reported by:  Ross Gohlke

Modified:
  head/sys/kern/kern_descrip.c
  head/sys/kern/vfs_mountroot.c
  head/sys/sys/filedesc.h

Modified: head/sys/kern/kern_descrip.c
==============================================================================
--- head/sys/kern/kern_descrip.c        Mon Apr 27 13:26:43 2020        
(r360373)
+++ head/sys/kern/kern_descrip.c        Mon Apr 27 13:54:00 2020        
(r360374)
@@ -3475,6 +3475,27 @@ pwd_ensure_dirs(void)
        pwd_drop(oldpwd);
 }
 
+void
+pwd_set_rootvnode(void)
+{
+       struct filedesc *fdp;
+       struct pwd *oldpwd, *newpwd;
+
+       fdp = curproc->p_fd;
+
+       newpwd = pwd_alloc();
+       FILEDESC_XLOCK(fdp);
+       oldpwd = FILEDESC_XLOCKED_LOAD_PWD(fdp);
+       vrefact(rootvnode);
+       newpwd->pwd_cdir = rootvnode;
+       vrefact(rootvnode);
+       newpwd->pwd_rdir = rootvnode;
+       pwd_fill(oldpwd, newpwd);
+       pwd_set(fdp, newpwd);
+       FILEDESC_XUNLOCK(fdp);
+       pwd_drop(oldpwd);
+}
+
 /*
  * Scan all active processes and prisons to see if any of them have a current
  * or root directory of `olddp'. If so, replace them with the new mount point.

Modified: head/sys/kern/vfs_mountroot.c
==============================================================================
--- head/sys/kern/vfs_mountroot.c       Mon Apr 27 13:26:43 2020        
(r360373)
+++ head/sys/kern/vfs_mountroot.c       Mon Apr 27 13:54:00 2020        
(r360374)
@@ -243,7 +243,7 @@ set_rootvnode(void)
 
        VOP_UNLOCK(rootvnode);
 
-       pwd_ensure_dirs();
+       pwd_set_rootvnode();
 }
 
 static int

Modified: head/sys/sys/filedesc.h
==============================================================================
--- head/sys/sys/filedesc.h     Mon Apr 27 13:26:43 2020        (r360373)
+++ head/sys/sys/filedesc.h     Mon Apr 27 13:54:00 2020        (r360374)
@@ -298,6 +298,7 @@ fd_modified(struct filedesc *fdp, int fd, seqc_t seqc)
 void   pwd_chdir(struct thread *td, struct vnode *vp);
 int    pwd_chroot(struct thread *td, struct vnode *vp);
 void   pwd_ensure_dirs(void);
+void   pwd_set_rootvnode(void);
 
 struct pwd *pwd_hold_filedesc(struct filedesc *fdp);
 struct pwd *pwd_hold(struct thread *td);
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to