bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 07/13] trans: return nodes locked when creating fake nodes in fak


From: Justus Winter
Subject: [PATCH 07/13] trans: return nodes locked when creating fake nodes in fakeroot
Date: Mon, 9 Dec 2013 15:16:35 +0100

* trans/fakeroot.c (new_node): Acquire the nodes lock before releasing
  the idport_ihash_lock.  Return nodes locked.
(netfs_S_dir_lookup): Drop lock.
(netfs_attempt_mkfile): Likewise.
(main): Likewise.
---
 trans/fakeroot.c |   16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/trans/fakeroot.c b/trans/fakeroot.c
index b97b499..1233104 100644
--- a/trans/fakeroot.c
+++ b/trans/fakeroot.c
@@ -61,7 +61,8 @@ struct hurd_ihash idport_ihash
   = HURD_IHASH_INITIALIZER (offsetof (struct netnode, idport_locp));
 
 
-/* Make a new virtual node.  Always consumes the ports.  */
+/* Make a new virtual node.  Always consumes the ports.  If
+   successful, NP will be locked.  */
 static error_t
 new_node (file_t file, mach_port_t idport, int locked, int openmodes,
          struct node **np)
@@ -107,7 +108,10 @@ new_node (file_t file, mach_port_t idport, int locked, int 
openmodes,
        pthread_mutex_lock (&idport_ihash_lock);
       err = hurd_ihash_add (&idport_ihash, nn->idport, nn);
       if (!err)
-       netfs_nref (*np);       /* Return a reference to the caller.  */
+       {
+         pthread_mutex_lock (&(*np)->lock);
+         netfs_nref (*np);     /* Return a reference to the caller.  */
+       }
       pthread_mutex_unlock (&idport_ihash_lock);
     }
   if (err)
@@ -330,7 +334,10 @@ netfs_S_dir_lookup (struct protid *diruser,
            {
              err = new_node (file, idport, 1, flags, &np);
              if (!err)
-               err = netfs_validate_stat (np, diruser->user);
+               {
+                 pthread_mutex_unlock (&np->lock);
+                 err = netfs_validate_stat (np, diruser->user);
+               }
            }
        }
     }
@@ -616,6 +623,8 @@ netfs_attempt_mkfile (struct iouser *user, struct node *dir,
                            real_from_fake_mode (mode), &newfile);
   if (err == 0)
     err = new_node (newfile, MACH_PORT_NULL, 0, O_RDWR|O_EXEC, np);
+  if (err == 0)
+    pthread_mutex_unlock (&(*np)->lock);
   pthread_mutex_unlock (&dir->lock);
   return err;
 }
@@ -962,6 +971,7 @@ any user to open nodes regardless of permissions as is done 
for root." };
   netfs_root_node->nn_stat.st_mode &= ~(S_IPTRANS | S_IATRANS);
   netfs_root_node->nn_stat.st_mode |= S_IROOT;
   netfs_root_node->nn->faked |= FAKE_MODE;
+  pthread_mutex_unlock (&netfs_root_node->lock);
 
   netfs_server_loop ();                /* Never returns.  */
 
-- 
1.7.10.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]