about summary refs log tree commit homepage
path: root/svc_dev.c
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2012-03-12 16:31:37 -0700
committerEric Wong <normalperson@yhbt.net>2012-03-12 19:08:44 -0700
commit93b3f4c03933fe11ca5d00c8262b79b192fc599c (patch)
tree29771e8864c7e5699e143c2076c0665e11f1ebcb /svc_dev.c
parentf108dac998b4d474b6a8ac1ce0f226caaf836c02 (diff)
downloadcmogstored-93b3f4c03933fe11ca5d00c8262b79b192fc599c.tar.gz
This matches the behavior of Perl mogstored.  Some
systems (like one of mine) may have many major devices
and fewer devices dedicated to MogileFS storage.

This really *should* be tunable, though...
Diffstat (limited to 'svc_dev.c')
-rw-r--r--svc_dev.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/svc_dev.c b/svc_dev.c
index fd933a4..ea541e0 100644
--- a/svc_dev.c
+++ b/svc_dev.c
@@ -30,7 +30,7 @@ static void svc_init_dev_hash(struct mog_svc *svc)
         if (!svc->by_st_dev) mog_oom();
 }
 
-int mog_svc_scandev(struct mog_svc *svc, mog_scandev_cb cb)
+static int svc_scandev(struct mog_svc *svc, size_t *nr, mog_scandev_cb cb)
 {
         struct dirent *ent;
         int rc = 0;
@@ -56,8 +56,12 @@ int mog_svc_scandev(struct mog_svc *svc, mog_scandev_cb cb)
 
                 if (cb) rc |= cb(dev, svc); /* mog_dev_mkusage */
                 switch (hash_insert_if_absent(svc->by_st_dev, dev, NULL)) {
-                case 0: free(dev);
-                case 1: break;
+                case 0:
+                        free(dev);
+                        break;
+                case 1:
+                        (*nr)++;
+                        break;
                 default: mog_oom(); /* -1 */
                 }
         }
@@ -169,3 +173,19 @@ void mog_svc_dev_shutdown(void)
 {
         mog_svc_each(devstats_shutdown_i, NULL);
 }
+
+static bool svc_mkusage_each(void *svc, void *nr)
+{
+        svc_scandev((struct mog_svc *)svc, nr, mog_dev_mkusage);
+
+        return true;
+}
+
+size_t mog_mkusage_all(void)
+{
+        size_t nr = 0;
+
+        mog_svc_each(svc_mkusage_each, &nr);
+
+        return nr;
+}