summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--storeio/ChangeLog10
-rw-r--r--storeio/dev.c5
-rw-r--r--storeio/dev.h8
-rw-r--r--storeio/storeio.c24
4 files changed, 39 insertions, 8 deletions
diff --git a/storeio/ChangeLog b/storeio/ChangeLog
index 5a0c51ba..43a300ab 100644
--- a/storeio/ChangeLog
+++ b/storeio/ChangeLog
@@ -1,3 +1,13 @@
+2001-02-18 Marcus Brinkmann <marcus@gnu.org>
+
+ * dev.h (struct dev): New member nperopens.
+ * storeio.c (open_hook): Hold device lock and check if this is the
+ first open. If yes, activate the store.
+ (close_hook): Hold global_lock and check if this was the last
+ open. If yes, inactivate the store.
+ * dev.c (dev_open): Open the store with STORE_INACTIVE
+ (in store_parsed_open as well as in store_create).
+
2001-01-17 Roland McGrath <roland@frob.com>
* dev.c (dev_buf_discard): Don't check AMOUNT if store_write failed.
diff --git a/storeio/dev.c b/storeio/dev.c
index fdfc0fbd..108e7dd3 100644
--- a/storeio/dev.c
+++ b/storeio/dev.c
@@ -145,14 +145,15 @@ dev_open (struct dev *dev)
/* This means we had no store arguments.
We are to operate on our underlying node. */
err = store_create (storeio_fsys->underlying,
- dev->readonly ? STORE_READONLY : 0,
+ STORE_INACTIVE | (dev->readonly ? STORE_READONLY : 0),
0, &dev->store);
}
else
/* Open based on the previously parsed store arguments. */
err = store_parsed_open (dev->store_name,
- dev->readonly ? STORE_READONLY : 0,
+ STORE_INACTIVE
+ | (dev->readonly ? STORE_READONLY : 0),
&dev->store);
if (err)
return err;
diff --git a/storeio/dev.h b/storeio/dev.h
index 7a64c54e..d5b9d1a4 100644
--- a/storeio/dev.h
+++ b/storeio/dev.h
@@ -50,8 +50,12 @@ struct dev
indicates that there is no owner. */
pid_t owner;
- /* This lock protects `store' and `owner'. The other members never
- change after creation, except for those locked by io_lock (below). */
+ /* The number of active opens. */
+ int nperopens;
+
+ /* This lock protects `store', `owner' and `nperopens'. The other
+ members never change after creation, except for those locked by
+ io_lock (below). */
struct mutex lock;
/* Nonzero iff the --no-cache flag was given.
diff --git a/storeio/storeio.c b/storeio/storeio.c
index 5b82a6c8..87bc249c 100644
--- a/storeio/storeio.c
+++ b/storeio/storeio.c
@@ -233,18 +233,34 @@ check_open_hook (struct trivfs_control *trivfs_control,
static error_t
open_hook (struct trivfs_peropen *peropen)
{
+ error_t err = 0;
struct dev *const dev = peropen->cntl->hook;
+
if (dev->store)
- return open_create (dev, (struct open **)&peropen->hook);
- else
- return 0;
+ {
+ mutex_lock (&dev->lock);
+ if (dev->nperopens++ == 0)
+ err = store_clear_flags (dev->store, STORE_INACTIVE);
+ mutex_unlock (&dev->lock);
+ if (!err)
+ err = open_create (dev, (struct open **)&peropen->hook);
+ }
+ return err;
}
static void
close_hook (struct trivfs_peropen *peropen)
{
+ struct dev *const dev = peropen->cntl->hook;
+
if (peropen->hook)
- open_free (peropen->hook);
+ {
+ mutex_lock (&dev->lock);
+ if (--dev->nperopens == 0)
+ store_set_flags (dev->store, STORE_INACTIVE);
+ mutex_unlock (&dev->lock);
+ open_free (peropen->hook);
+ }
}
/* ---------------------------------------------------------------- */