From 82781dd6da2b6a1eb113e20d100052509bb85a90 Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Thu, 19 Apr 2001 22:11:52 +0000 Subject: 2001-02-18 Marcus Brinkmann * 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). --- storeio/ChangeLog | 10 ++++++++++ storeio/dev.c | 5 +++-- storeio/dev.h | 8 ++++++-- storeio/storeio.c | 24 ++++++++++++++++++++---- 4 files changed, 39 insertions(+), 8 deletions(-) (limited to 'storeio') 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 + + * 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 * 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); + } } /* ---------------------------------------------------------------- */ -- cgit v1.2.3