[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[hurd] 06/17: Use refcount_t for peropen reference counting in libnetfs.
From: |
Samuel Thibault |
Subject: |
[hurd] 06/17: Use refcount_t for peropen reference counting in libnetfs. |
Date: |
Mon, 15 Feb 2016 09:10:02 +0000 |
This is an automated email from the git hooks/post-receive script.
sthibault pushed a commit to branch upstream
in repository hurd.
commit afea5285b0e40b68f97b47f0f0edc471b554fb34
Author: Flavio Cruz <address@hidden>
Date: Sun Feb 7 01:33:00 2016 -0500
Use refcount_t for peropen reference counting in libnetfs.
* libnetfs/netfs.h: Use refcount_t.
* libnetfs/make-peropen.c: Initialize to 1 with refcount_init just like in
libdiskfs.
* libnetfs/make-protid.c: Don't increment the count here. Do it like
libdiskfs.
* libnetfs/io-duplicate.c: Add refcount_ref since netfs_make_protid no
longer increments the refcount.
* libnetfs/io-reauthenticate.c: Likewise.
* libnetfs/io-restrict-auth.c: Likewise.
* libnetfs/release-peropen.c: Dereference without locking.
---
libnetfs/io-duplicate.c | 1 +
libnetfs/io-reauthenticate.c | 2 ++
libnetfs/io-restrict-auth.c | 2 ++
libnetfs/make-peropen.c | 2 +-
libnetfs/make-protid.c | 1 -
libnetfs/netfs.h | 2 +-
libnetfs/release-peropen.c | 38 ++++++++++++++++++--------------------
7 files changed, 25 insertions(+), 23 deletions(-)
diff --git a/libnetfs/io-duplicate.c b/libnetfs/io-duplicate.c
index b2c3a3a..263f9e8 100644
--- a/libnetfs/io-duplicate.c
+++ b/libnetfs/io-duplicate.c
@@ -34,6 +34,7 @@ netfs_S_io_duplicate (struct protid *user,
if (err)
return err;
+ refcount_ref (&user->po->refcnt);
pthread_mutex_lock (&user->po->np->lock);
newpi = netfs_make_protid (user->po, clone);
*newport = ports_get_right (newpi);
diff --git a/libnetfs/io-reauthenticate.c b/libnetfs/io-reauthenticate.c
index 8ff4182..b2d4a44 100644
--- a/libnetfs/io-reauthenticate.c
+++ b/libnetfs/io-reauthenticate.c
@@ -34,12 +34,14 @@ netfs_S_io_reauthenticate (struct protid *user, mach_port_t
rend_port)
/* This routine must carefully ignore EINTR because we
are a simpleroutine, so callers won't know to restart. */
+ refcount_ref (&user->po->refcnt);
pthread_mutex_lock (&user->po->np->lock);
do
newpi = netfs_make_protid (user->po, 0);
while (! newpi && errno == EINTR);
if (! newpi)
{
+ refcount_deref (&user->po->refcnt);
pthread_mutex_unlock (&user->po->np->lock);
return errno;
}
diff --git a/libnetfs/io-restrict-auth.c b/libnetfs/io-restrict-auth.c
index 0c3403d..79b7d09 100644
--- a/libnetfs/io-restrict-auth.c
+++ b/libnetfs/io-restrict-auth.c
@@ -43,6 +43,7 @@ netfs_S_io_restrict_auth (struct protid *user,
return err;
pthread_mutex_lock (&user->po->np->lock);
+ refcount_ref (&user->po->refcnt);
newpi = netfs_make_protid (user->po, new_user);
if (newpi)
{
@@ -52,6 +53,7 @@ netfs_S_io_restrict_auth (struct protid *user,
}
else
{
+ refcount_deref (&user->po->refcnt);
pthread_mutex_unlock (&user->po->np->lock);
iohelp_free_iouser (new_user);
err = ENOMEM;
diff --git a/libnetfs/make-peropen.c b/libnetfs/make-peropen.c
index f7be58b..413e914 100644
--- a/libnetfs/make-peropen.c
+++ b/libnetfs/make-peropen.c
@@ -31,7 +31,7 @@ netfs_make_peropen (struct node *np, int flags, struct
peropen *context)
po->filepointer = 0;
po->lock_status = LOCK_UN;
- po->refcnt = 0;
+ refcount_init (&po->refcnt, 1);
po->openstat = flags;
po->np = np;
po->path = NULL;
diff --git a/libnetfs/make-protid.c b/libnetfs/make-protid.c
index bf18283..995ac1e 100644
--- a/libnetfs/make-protid.c
+++ b/libnetfs/make-protid.c
@@ -36,7 +36,6 @@ netfs_make_protid (struct peropen *po, struct iouser *cred)
if (errno)
return 0;
- po->refcnt++;
pi->po = po;
pi->user = cred;
pi->shared_object = MACH_PORT_NULL;
diff --git a/libnetfs/netfs.h b/libnetfs/netfs.h
index fbe2c60..3f94ccd 100644
--- a/libnetfs/netfs.h
+++ b/libnetfs/netfs.h
@@ -51,7 +51,7 @@ struct peropen
{
loff_t filepointer;
int lock_status;
- int refcnt;
+ refcount_t refcnt;
int openstat;
struct node *np;
diff --git a/libnetfs/release-peropen.c b/libnetfs/release-peropen.c
index c206b43..01af97d 100644
--- a/libnetfs/release-peropen.c
+++ b/libnetfs/release-peropen.c
@@ -24,29 +24,27 @@
void
netfs_release_peropen (struct peropen *po)
{
+ if (refcount_deref (&po->refcnt) > 0)
+ return;
+
pthread_mutex_lock (&po->np->lock);
- if (--po->refcnt)
- pthread_mutex_unlock (&po->np->lock);
- else
- {
- if (po->root_parent)
- mach_port_deallocate (mach_task_self (), po->root_parent);
+ if (po->root_parent)
+ mach_port_deallocate (mach_task_self (), po->root_parent);
- if (po->shadow_root && po->shadow_root != po->np)
- {
- pthread_mutex_lock (&po->shadow_root->lock);
- netfs_nput (po->shadow_root);
- }
- if (po->shadow_root_parent)
- mach_port_deallocate (mach_task_self (), po->shadow_root_parent);
+ if (po->shadow_root && po->shadow_root != po->np)
+ {
+ pthread_mutex_lock (&po->shadow_root->lock);
+ netfs_nput (po->shadow_root);
+ }
+ if (po->shadow_root_parent)
+ mach_port_deallocate (mach_task_self (), po->shadow_root_parent);
- if (po->lock_status != LOCK_UN)
- fshelp_acquire_lock (&po->np->userlock, &po->lock_status,
- &po->np->lock, LOCK_UN);
+ if (po->lock_status != LOCK_UN)
+ fshelp_acquire_lock (&po->np->userlock, &po->lock_status,
+ &po->np->lock, LOCK_UN);
- netfs_nput (po->np);
+ netfs_nput (po->np);
- free (po->path);
- free (po);
- }
+ free (po->path);
+ free (po);
}
--
Alioth's /usr/local/bin/git-commit-notice on
/srv/git.debian.org/git/pkg-hurd/hurd.git
- [hurd] 02/17: Fix typo, (continued)
- [hurd] 02/17: Fix typo, Samuel Thibault, 2016/02/15
- [hurd] 16/17: Fix function name, Samuel Thibault, 2016/02/15
- [hurd] 14/17: Make sure to complete auth_server_authenticate, Samuel Thibault, 2016/02/15
- [hurd] 15/17: Fix hang on reauthentication, Samuel Thibault, 2016/02/15
- [hurd] 05/17: utils/settrans: improve --chroot functionality, Samuel Thibault, 2016/02/15
- [hurd] 08/17: mach-defpager: link dynamically, Samuel Thibault, 2016/02/15
- [hurd] 09/17: devnode: fix falling back to the kernel driver, Samuel Thibault, 2016/02/15
- [hurd] 01/17: Also build exec.static, Samuel Thibault, 2016/02/15
- [hurd] 12/17: utils/vmallocate: new utility, Samuel Thibault, 2016/02/15
- [hurd] 17/17: Merge remote-tracking branch 'upstream/master' into upstream, Samuel Thibault, 2016/02/15
- [hurd] 06/17: Use refcount_t for peropen reference counting in libnetfs.,
Samuel Thibault <=
- [hurd] 07/17: Remove libfshelp/trans.h and libfshelp/locks.h., Samuel Thibault, 2016/02/15
- [hurd] 10/17: Check for a return value in netfs_make_peropen before using it in netfs_make_protid., Samuel Thibault, 2016/02/15
- [hurd] 13/17: Use libihash to store directory entries in ftpfs., Samuel Thibault, 2016/02/15