Whamcloud - gitweb
LU-1378 fld: export fldb under /proc
authorwangdi <di.wang@whamcloud.com>
Fri, 22 Jun 2012 14:58:47 +0000 (07:58 -0700)
committerAndreas Dilger <adilger@whamcloud.com>
Tue, 10 Jul 2012 17:05:24 +0000 (13:05 -0400)
Export fldb under /proc.

Signed-off-by: wang di <di.wang@whamcloud.com>
Change-Id: Ie4e877fb707cbd86ca83841fffa98425b8f66c00
Reviewed-on: http://review.whamcloud.com/3175
Tested-by: Hudson
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Bobi Jam <bobijam@whamcloud.com>
Tested-by: Maloo <whamcloud.maloo@gmail.com>
lustre/fid/lproc_fid.c
lustre/fld/fld_handler.c
lustre/fld/fld_index.c
lustre/fld/fld_internal.h
lustre/fld/lproc_fld.c
lustre/include/lustre/lustre_idl.h

index 83e701d..7d3d1bb 100644 (file)
@@ -33,6 +33,8 @@
  * This file is part of Lustre, http://www.lustre.org/
  * Lustre is a trademark of Sun Microsystems, Inc.
  *
+ * Copyright (c) 2011, 2012, Whamcloud, Inc.
+ *
  * lustre/fid/lproc_fid.c
  *
  * Lustre Sequence Manager
@@ -92,8 +94,8 @@ seq_proc_read_common(char *page, char **start, off_t off,
        ENTRY;
 
         *eof = 1;
-        rc = snprintf(page, count, "["LPX64" - "LPX64"]:%x:%x\n",
-                      PRANGE(range));
+       rc = snprintf(page, count, "["LPX64" - "LPX64"]:%x:%s\n",
+                       PRANGE(range));
        RETURN(rc);
 }
 
index fd83f96..9f3f1ef 100644 (file)
@@ -492,7 +492,14 @@ static int fld_server_proc_init(struct lu_server_fld *fld)
                 RETURN(rc);
         }
 
-        RETURN(rc);
+       rc = lprocfs_seq_create(fld->lsf_proc_dir, "fldb", 0444,
+                               &fld_proc_seq_fops, fld);
+       if (rc) {
+               lprocfs_remove(&fld->lsf_proc_dir);
+               fld->lsf_proc_dir = NULL;
+       }
+
+       RETURN(rc);
 }
 
 static void fld_server_proc_fini(struct lu_server_fld *fld)
index bd44fd0..2c3ebe8 100644 (file)
@@ -82,8 +82,7 @@ const struct dt_index_features fld_index_features = {
 
 extern struct lu_context_key fld_thread_key;
 
-static struct dt_key *fld_key(const struct lu_env *env,
-                              const seqno_t seq)
+static struct dt_key *fld_key(const struct lu_env *env, const seqno_t seq)
 {
         struct fld_thread_info *info;
         ENTRY;
index b267949..a2975d0 100644 (file)
@@ -157,6 +157,8 @@ int fld_trans_start(struct lu_server_fld *fld,
 void fld_trans_stop(struct lu_server_fld *fld,
                     const struct lu_env *env, struct thandle* th);
 
+extern struct lu_context_key fld_thread_key;
+
 int fld_index_init(struct lu_server_fld *fld,
                    const struct lu_env *env,
                    struct dt_device *dt);
@@ -214,5 +216,5 @@ fld_target_name(struct lu_fld_target *tar)
 }
 
 extern cfs_proc_dir_entry_t *fld_type_proc_dir;
-
+extern struct file_operations fld_proc_seq_fops;
 #endif /* __FLD_INTERNAL_H */
index 09024dd..7b784eb 100644 (file)
@@ -26,6 +26,8 @@
 /*
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, 2012, Whamcloud, Inc.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -36,6 +38,7 @@
  * FLD (FIDs Location Database)
  *
  * Author: Yury Umanets <umka@clusterfs.com>
+ *     Di Wang <di.wang@whamcloud.com>
  */
 
 #define DEBUG_SUBSYSTEM S_FLD
@@ -54,6 +57,7 @@
 #include <obd_support.h>
 #include <lustre_req_layout.h>
 #include <lustre_fld.h>
+#include <lustre_fid.h>
 #include "fld_internal.h"
 
 #ifdef LPROCFS
@@ -131,7 +135,7 @@ fld_proc_write_hash(struct file *file, const char *buffer,
                 CDEBUG(D_INFO, "%s: Changed hash to \"%s\"\n",
                        fld->lcf_name, hash->fh_name);
         }
-       
+
         RETURN(count);
 }
 
@@ -147,10 +151,156 @@ fld_proc_write_cache_flush(struct file *file, const char *buffer,
         fld_cache_flush(fld->lcf_cache);
 
         CDEBUG(D_INFO, "%s: Lookup cache is flushed\n", fld->lcf_name);
-       
+
         RETURN(count);
 }
 
+struct fld_seq_param {
+       struct lu_env  fsp_env;
+       struct dt_it  *fsp_it;
+};
+
+static void *fldb_seq_start(struct seq_file *p, loff_t *pos)
+{
+       struct lu_server_fld    *fld = p->private;
+       struct dt_object        *obj;
+       const struct dt_it_ops  *iops;
+       struct fld_seq_param    *param;
+       struct fld_thread_info  *info;
+
+       if (fld->lsf_obj == NULL)
+               return NULL;
+
+       obj = fld->lsf_obj;
+       iops = &obj->do_index_ops->dio_it;
+
+       OBD_ALLOC_PTR(param);
+       if (param == NULL)
+               return ERR_PTR(-ENOMEM);
+
+       lu_env_init(&param->fsp_env, LCT_MD_THREAD);
+       param->fsp_it = iops->init(&param->fsp_env, obj, 0, NULL);
+       info = lu_context_key_get(&param->fsp_env.le_ctx,
+                                 &fld_thread_key);
+
+       iops->load(&param->fsp_env, param->fsp_it, *pos);
+
+       return param;
+}
+
+static void fldb_seq_stop(struct seq_file *p, void *v)
+{
+       struct lu_server_fld    *fld = p->private;
+       struct dt_object        *obj;
+       const struct dt_it_ops  *iops;
+       struct fld_seq_param    *param = (struct fld_seq_param *)v;
+
+       if (fld->lsf_obj == NULL)
+               return;
+
+       obj = fld->lsf_obj;
+       iops = &obj->do_index_ops->dio_it;
+       if (IS_ERR(param) || param == NULL)
+               return;
+
+       iops->put(&param->fsp_env, param->fsp_it);
+       iops->fini(&param->fsp_env, param->fsp_it);
+       lu_env_fini(&param->fsp_env);
+       OBD_FREE_PTR(param);
+
+       return;
+}
+
+static void *fldb_seq_next(struct seq_file *p, void *v, loff_t *pos)
+{
+       struct lu_server_fld    *fld = p->private;
+       struct dt_object        *obj;
+       const struct dt_it_ops  *iops;
+       struct fld_seq_param    *param = (struct fld_seq_param *)v;
+       int                     rc;
+
+       if (fld->lsf_obj == NULL)
+               return NULL;
+
+       obj = fld->lsf_obj;
+       iops = &obj->do_index_ops->dio_it;
+
+       iops->get(&param->fsp_env, param->fsp_it,
+                 (const struct dt_key *)pos);
+
+       rc = iops->next(&param->fsp_env, param->fsp_it);
+       if (rc > 0) {
+               iops->put(&param->fsp_env, param->fsp_it);
+               iops->fini(&param->fsp_env, param->fsp_it);
+               lu_env_fini(&param->fsp_env);
+               OBD_FREE_PTR(param);
+               return NULL;
+       }
+
+       *pos = *(loff_t *)iops->key(&param->fsp_env, param->fsp_it);
+
+       return param;
+}
+
+static int fldb_seq_show(struct seq_file *p, void *v)
+{
+       struct lu_server_fld    *fld = p->private;
+       struct dt_object        *obj = fld->lsf_obj;
+       struct fld_seq_param    *param = (struct fld_seq_param *)v;
+       const struct dt_it_ops  *iops;
+       struct fld_thread_info  *info;
+       struct lu_seq_range     *fld_rec;
+       int                     rc;
+
+       if (fld->lsf_obj == NULL)
+               return 0;
+
+       obj = fld->lsf_obj;
+       iops = &obj->do_index_ops->dio_it;
+
+       info = lu_context_key_get(&param->fsp_env.le_ctx,
+                                 &fld_thread_key);
+       fld_rec = &info->fti_rec;
+       rc = iops->rec(&param->fsp_env, param->fsp_it,
+                      (struct dt_rec *)fld_rec, 0);
+       if (rc != 0) {
+               CERROR("%s:read record error: rc %d\n",
+                      fld->lsf_name, rc);
+       } else if (fld_rec->lsr_start != 0) {
+               range_be_to_cpu(fld_rec, fld_rec);
+               rc = seq_printf(p, DRANGE"\n", PRANGE(fld_rec));
+       }
+
+       iops->put(&param->fsp_env, param->fsp_it);
+
+       return rc;
+}
+
+struct seq_operations fldb_sops = {
+       .start = fldb_seq_start,
+       .stop = fldb_seq_stop,
+       .next = fldb_seq_next,
+       .show = fldb_seq_show,
+};
+
+static int fldb_seq_open(struct inode *inode, struct file *file)
+{
+       struct proc_dir_entry *dp = PDE(inode);
+       struct seq_file *seq;
+       int rc;
+
+       LPROCFS_ENTRY_AND_CHECK(dp);
+       rc = seq_open(file, &fldb_sops);
+       if (rc) {
+               LPROCFS_EXIT();
+               return rc;
+       }
+
+       seq = file->private_data;
+       seq->private = dp->data;
+       return 0;
+}
+
 struct lprocfs_vars fld_server_proc_list[] = {
        { NULL }};
 
@@ -159,4 +309,13 @@ struct lprocfs_vars fld_client_proc_list[] = {
        { "hash",        fld_proc_read_hash, fld_proc_write_hash, NULL },
        { "cache_flush", NULL, fld_proc_write_cache_flush, NULL },
        { NULL }};
+
+struct file_operations fld_proc_seq_fops = {
+       .owner   = THIS_MODULE,
+       .open    = fldb_seq_open,
+       .read    = seq_read,
+       .llseek  = seq_lseek,
+       .release = lprocfs_seq_release,
+};
+
 #endif
index 7cb1477..6a390d8 100644 (file)
@@ -251,13 +251,14 @@ static inline int range_compare_loc(const struct lu_seq_range *r1,
                r1->lsr_flags != r2->lsr_flags;
 }
 
-#define DRANGE "[%#16.16"LPF64"x-%#16.16"LPF64"x):%x:%x"
+#define DRANGE "[%#16.16"LPF64"x-%#16.16"LPF64"x):%x:%s"
 
 #define PRANGE(range)      \
-        (range)->lsr_start, \
-        (range)->lsr_end,    \
-        (range)->lsr_index,  \
-        (range)->lsr_flags
+       (range)->lsr_start, \
+       (range)->lsr_end,    \
+       (range)->lsr_index,  \
+       (range)->lsr_flags == LU_SEQ_RANGE_MDT ? "mdt" : "ost"
+
 
 /** \defgroup lu_fid lu_fid
  * @{ */