Whamcloud - gitweb
b=1028 drop SOM dependency on quota
[fs/lustre-release.git] / lustre / mdt / mdt_lproc.c
index 23624be..cb8ff1f 100644 (file)
@@ -74,31 +74,63 @@ static const char *mdt_proc_names[LPROC_MDT_NR] = {
 int mdt_procfs_init(struct mdt_device *mdt, const char *name)
 {
         struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev;
-        int result;
+        struct obd_device *obd = ld->ld_obd;
+        struct lprocfs_static_vars lvars;
+        int rc;
         ENTRY;
 
         LASSERT(name != NULL);
-        mdt->mdt_proc_entry = ld->ld_obd->obd_proc_entry;
+
+        lprocfs_mdt_init_vars(&lvars);
+        rc = lprocfs_obd_setup(obd, lvars.obd_vars);
+        if (rc) {
+                CERROR("Can't init lprocfs, rc %d\n", rc);
+                return rc;
+        }
+        ptlrpc_lprocfs_register_obd(obd);
+
+        mdt->mdt_proc_entry = obd->obd_proc_entry;
         LASSERT(mdt->mdt_proc_entry != NULL);
 
-        result = lu_time_init(&mdt->mdt_stats, mdt->mdt_proc_entry,
-                              mdt_proc_names, ARRAY_SIZE(mdt_proc_names));
-        if (result == 0)
-                result = lu_time_named_init(&ld->ld_site->ls_time_stats,
-                                            "site_time", mdt->mdt_proc_entry,
-                                            lu_time_names,
-                                            ARRAY_SIZE(lu_time_names));
-        RETURN(result);
+        rc = lu_time_init(&mdt->mdt_stats, mdt->mdt_proc_entry,
+                          mdt_proc_names, ARRAY_SIZE(mdt_proc_names));
+        if (rc == 0)
+                rc = lu_time_named_init(&ld->ld_site->ls_time_stats,
+                                        "site_time", mdt->mdt_proc_entry,
+                                         lu_time_names,
+                                         ARRAY_SIZE(lu_time_names));
+        if (rc)
+                return rc;
+
+        obd->obd_proc_exports_entry = proc_mkdir("exports",
+                                                 obd->obd_proc_entry);
+        if (obd->obd_proc_exports_entry)
+                lprocfs_add_simple(obd->obd_proc_exports_entry,
+                                   "clear", lprocfs_nid_stats_clear_read,
+                                   lprocfs_nid_stats_clear_write, obd, NULL);
+        rc = lprocfs_alloc_md_stats(obd, LPROC_MDT_NR);
+
+        RETURN(rc);
 }
 
 int mdt_procfs_fini(struct mdt_device *mdt)
 {
         struct lu_device *ld = &mdt->mdt_md_dev.md_lu_dev;
+        struct obd_device *obd = ld->ld_obd;
+
         if (mdt->mdt_proc_entry) {
                 lu_time_fini(&ld->ld_site->ls_time_stats);
                 lu_time_fini(&mdt->mdt_stats);
                 mdt->mdt_proc_entry = NULL;
         }
+        if (obd->obd_proc_exports_entry) {
+                lprocfs_remove_proc_entry("clear", obd->obd_proc_exports_entry);
+                obd->obd_proc_exports_entry = NULL;
+        }
+        ptlrpc_lprocfs_unregister_obd(obd);
+        lprocfs_free_md_stats(obd);
+        lprocfs_obd_cleanup(obd);
+
         RETURN(0);
 }
 
@@ -120,7 +152,7 @@ static int lprocfs_rd_identity_expire(char *page, char **start, off_t off,
 
         *eof = 1;
         return snprintf(page, count, "%lu\n",
-                        mdt->mdt_identity_cache->uc_entry_expire / HZ);
+                        mdt->mdt_identity_cache->uc_entry_expire / CFS_HZ);
 }
 
 static int lprocfs_wr_identity_expire(struct file *file, const char *buffer,
@@ -134,7 +166,7 @@ static int lprocfs_wr_identity_expire(struct file *file, const char *buffer,
         if (rc)
                 return rc;
 
-        mdt->mdt_identity_cache->uc_entry_expire = val * HZ;
+        mdt->mdt_identity_cache->uc_entry_expire = val * CFS_HZ;
         return count;
 }
 
@@ -147,7 +179,7 @@ static int lprocfs_rd_identity_acquire_expire(char *page, char **start,
 
         *eof = 1;
         return snprintf(page, count, "%lu\n",
-                        mdt->mdt_identity_cache->uc_acquire_expire / HZ);
+                        mdt->mdt_identity_cache->uc_acquire_expire / CFS_HZ);
 }
 
 static int lprocfs_wr_identity_acquire_expire(struct file *file,
@@ -163,7 +195,7 @@ static int lprocfs_wr_identity_acquire_expire(struct file *file,
         if (rc)
                 return rc;
 
-        mdt->mdt_identity_cache->uc_acquire_expire = val * HZ;
+        mdt->mdt_identity_cache->uc_acquire_expire = val * CFS_HZ;
         return count;
 }
 
@@ -176,9 +208,9 @@ static int lprocfs_rd_identity_upcall(char *page, char **start, off_t off,
         int len;
 
         *eof = 1;
-        read_lock(&hash->uc_upcall_rwlock);
+        cfs_read_lock(&hash->uc_upcall_rwlock);
         len = snprintf(page, count, "%s\n", hash->uc_upcall);
-        read_unlock(&hash->uc_upcall_rwlock);
+        cfs_read_unlock(&hash->uc_upcall_rwlock);
         return len;
 }
 
@@ -195,14 +227,15 @@ static int lprocfs_wr_identity_upcall(struct file *file, const char *buffer,
                 return -EINVAL;
         }
 
-        if (copy_from_user(kernbuf, buffer, min_t(unsigned long, count,
-                                                  UC_CACHE_UPCALL_MAXPATH - 1)))
+        if (cfs_copy_from_user(kernbuf, buffer,
+                               min_t(unsigned long, count,
+                                     UC_CACHE_UPCALL_MAXPATH - 1)))
                 return -EFAULT;
 
         /* Remove any extraneous bits from the upcall (e.g. linefeeds) */
-        write_lock(&hash->uc_upcall_rwlock);
+        cfs_write_lock(&hash->uc_upcall_rwlock);
         sscanf(kernbuf, "%s", hash->uc_upcall);
-        write_unlock(&hash->uc_upcall_rwlock);
+        cfs_write_unlock(&hash->uc_upcall_rwlock);
 
         if (strcmp(hash->uc_name, obd->obd_name) != 0)
                 CWARN("%s: write to upcall name %s\n",
@@ -244,7 +277,7 @@ static int lprocfs_wr_identity_info(struct file *file, const char *buffer,
                 return count;
         }
 
-        if (copy_from_user(&sparam, buffer, sizeof(sparam))) {
+        if (cfs_copy_from_user(&sparam, buffer, sizeof(sparam))) {
                 CERROR("%s: bad identity data\n", obd->obd_name);
                 GOTO(out, rc = -EFAULT);
         }
@@ -276,7 +309,7 @@ static int lprocfs_wr_identity_info(struct file *file, const char *buffer,
                                sparam.idd_uid, sparam.idd_ngroups);
                         param = &sparam;
                         param->idd_ngroups = 0;
-                } else if (copy_from_user(param, buffer, size)) {
+                } else if (cfs_copy_from_user(param, buffer, size)) {
                         CERROR("%s: uid %u bad supplementary group data\n",
                                obd->obd_name, sparam.idd_uid);
                         OBD_FREE(param, size);
@@ -525,7 +558,7 @@ static int lprocfs_wr_root_squash(struct file *file, const char *buffer,
                 errmsg = "string too long";
                 GOTO(failed, rc = -EINVAL);
         }
-        if (copy_from_user(kernbuf, buffer, count)) {
+        if (cfs_copy_from_user(kernbuf, buffer, count)) {
                 errmsg = "bad address";
                 GOTO(failed, rc = -EFAULT);
         }
@@ -586,7 +619,7 @@ static int lprocfs_wr_nosquash_nids(struct file *file, const char *buffer,
         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
         int rc;
         char *kernbuf, *errmsg;
-        struct list_head tmp;
+        cfs_list_t tmp;
         ENTRY;
 
         OBD_ALLOC(kernbuf, count + 1);
@@ -594,7 +627,7 @@ static int lprocfs_wr_nosquash_nids(struct file *file, const char *buffer,
                 errmsg = "no memory";
                 GOTO(failed, rc = -ENOMEM);
         }
-        if (copy_from_user(kernbuf, buffer, count)) {
+        if (cfs_copy_from_user(kernbuf, buffer, count)) {
                 errmsg = "bad address";
                 GOTO(failed, rc = -EFAULT);
         }
@@ -602,15 +635,15 @@ static int lprocfs_wr_nosquash_nids(struct file *file, const char *buffer,
 
         if (!strcmp(kernbuf, "NONE") || !strcmp(kernbuf, "clear")) {
                 /* empty string is special case */
-                down_write(&mdt->mdt_squash_sem);
-                if (!list_empty(&mdt->mdt_nosquash_nids)) {
+                cfs_down_write(&mdt->mdt_squash_sem);
+                if (!cfs_list_empty(&mdt->mdt_nosquash_nids)) {
                         cfs_free_nidlist(&mdt->mdt_nosquash_nids);
                         OBD_FREE(mdt->mdt_nosquash_str,
                                  mdt->mdt_nosquash_strlen);
                         mdt->mdt_nosquash_str = NULL;
                         mdt->mdt_nosquash_strlen = 0;
                 }
-                up_write(&mdt->mdt_squash_sem);
+                cfs_up_write(&mdt->mdt_squash_sem);
                 LCONSOLE_INFO("%s: nosquash_nids is cleared\n",
                               obd->obd_name);
                 OBD_FREE(kernbuf, count + 1);
@@ -623,18 +656,18 @@ static int lprocfs_wr_nosquash_nids(struct file *file, const char *buffer,
                 GOTO(failed, rc = -EINVAL);
         }
 
-        down_write(&mdt->mdt_squash_sem);
-        if (!list_empty(&mdt->mdt_nosquash_nids)) {
+        cfs_down_write(&mdt->mdt_squash_sem);
+        if (!cfs_list_empty(&mdt->mdt_nosquash_nids)) {
                 cfs_free_nidlist(&mdt->mdt_nosquash_nids);
                 OBD_FREE(mdt->mdt_nosquash_str, mdt->mdt_nosquash_strlen);
         }
         mdt->mdt_nosquash_str = kernbuf;
         mdt->mdt_nosquash_strlen = count + 1;
-        list_splice(&tmp, &mdt->mdt_nosquash_nids);
+        cfs_list_splice(&tmp, &mdt->mdt_nosquash_nids);
 
         LCONSOLE_INFO("%s: nosquash_nids is set to %s\n",
                       obd->obd_name, kernbuf);
-        up_write(&mdt->mdt_squash_sem);
+        cfs_up_write(&mdt->mdt_squash_sem);
         RETURN(count);
 
  failed:
@@ -655,19 +688,6 @@ static int lprocfs_rd_mdt_som(char *page, char **start, off_t off,
                         mdt->mdt_som_conf ? "en" : "dis");
 }
 
-static int mdt_quota_off(struct mdt_device *mdt)
-{
-        struct md_device *next = mdt->mdt_child;
-        const struct md_quota_operations *mqo = &next->md_ops->mdo_quota;
-        struct lu_env env;
-        int rc;
-
-        lu_env_init(&env, LCT_MD_THREAD);
-        rc = mqo->mqo_off(&env, next, UGQUOTA | IMMQUOTA);
-        lu_env_fini(&env);
-        return rc;
-}
-
 static int lprocfs_wr_mdt_som(struct file *file, const char *buffer,
                               unsigned long count, void *data)
 {
@@ -676,12 +696,11 @@ static int lprocfs_wr_mdt_som(struct file *file, const char *buffer,
         struct mdt_device *mdt = mdt_dev(obd->obd_lu_dev);
         char kernbuf[16];
         unsigned long val = 0;
-        int rc;
 
         if (count > (sizeof(kernbuf) - 1))
                 return -EINVAL;
 
-        if (copy_from_user(kernbuf, buffer, count))
+        if (cfs_copy_from_user(kernbuf, buffer, count))
                 return -EFAULT;
 
         kernbuf[count] = '\0';
@@ -701,7 +720,7 @@ static int lprocfs_wr_mdt_som(struct file *file, const char *buffer,
         }
 
         /* 1 stands for self export. */
-        list_for_each_entry(exp, &obd->obd_exports, exp_obd_chain) {
+        cfs_list_for_each_entry(exp, &obd->obd_exports, exp_obd_chain) {
                 if (exp == obd->obd_self_export)
                         continue;
                 if (exp->exp_connect_flags & OBD_CONNECT_MDS_MDS)
@@ -713,13 +732,6 @@ static int lprocfs_wr_mdt_som(struct file *file, const char *buffer,
                 return count;
         }
 
-        if ((rc = mdt_quota_off(mdt))) {
-                if (rc == -EALREADY)
-                        rc = 0;
-                else
-                        return rc;
-        }
-
         mdt->mdt_som_conf = val;
         LCONSOLE_INFO("Enabling SOM\n");
 
@@ -738,7 +750,7 @@ static int lprocfs_mdt_wr_mdc(struct file *file, const char *buffer,
         sscanf(buffer, "%40s", tmpbuf);
 
         obd_str2uuid(&uuid, tmpbuf);
-        exp = lustre_hash_lookup(obd->obd_uuid_hash, &uuid);
+        exp = cfs_hash_lookup(obd->obd_uuid_hash, &uuid);
         if (exp == NULL) {
                 CERROR("%s: no export %s found\n",
                        obd->obd_name, obd_uuid2str(&uuid));