Whamcloud - gitweb
LU-4431 lnet: 1/3/2014 update for Cray interconnects
[fs/lustre-release.git] / lustre / osp / lproc_osp.c
index 21839f4..75ebeb1 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2012, Intel, Inc.
+ * Copyright (c) 2012, 2013, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -201,7 +201,7 @@ static int osp_rd_create_count(char *page, char **start, off_t off, int count,
        struct obd_device *obd = data;
        struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
 
-       if (osp == NULL)
+       if (osp == NULL || osp->opd_pre == NULL)
                return 0;
 
        return snprintf(page, count, "%d\n", osp->opd_pre_grow_count);
@@ -214,7 +214,7 @@ static int osp_wr_create_count(struct file *file, const char *buffer,
        struct osp_device       *osp = lu2osp_dev(obd->obd_lu_dev);
        int                      val, rc, i;
 
-       if (osp == NULL)
+       if (osp == NULL || osp->opd_pre == NULL)
                return 0;
 
        rc = lprocfs_write_helper(buffer, count, &val);
@@ -249,7 +249,7 @@ static int osp_rd_max_create_count(char *page, char **start, off_t off,
        struct obd_device *obd = data;
        struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
 
-       if (osp == NULL)
+       if (osp == NULL || osp->opd_pre == NULL)
                return 0;
 
        return snprintf(page, count, "%d\n", osp->opd_pre_max_grow_count);
@@ -262,7 +262,7 @@ static int osp_wr_max_create_count(struct file *file, const char *buffer,
        struct osp_device       *osp = lu2osp_dev(obd->obd_lu_dev);
        int                      val, rc;
 
-       if (osp == NULL)
+       if (osp == NULL || osp->opd_pre == NULL)
                return 0;
 
        rc = lprocfs_write_helper(buffer, count, &val);
@@ -288,10 +288,11 @@ static int osp_rd_prealloc_next_id(char *page, char **start, off_t off,
        struct obd_device *obd = data;
        struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
 
-       if (osp == NULL)
+       if (osp == NULL || osp->opd_pre == NULL)
                return 0;
 
-       return snprintf(page, count, LPU64"\n", osp->opd_pre_next);
+       return snprintf(page, count, "%u\n",
+                       fid_oid(&osp->opd_pre_used_fid) + 1);
 }
 
 static int osp_rd_prealloc_last_id(char *page, char **start, off_t off,
@@ -300,10 +301,37 @@ static int osp_rd_prealloc_last_id(char *page, char **start, off_t off,
        struct obd_device *obd = data;
        struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
 
-       if (osp == NULL)
+       if (osp == NULL || osp->opd_pre == NULL)
+               return 0;
+
+       return snprintf(page, count, "%u\n",
+                       fid_oid(&osp->opd_pre_last_created_fid));
+}
+
+static int osp_rd_prealloc_next_seq(char *page, char **start, off_t off,
+                                   int count, int *eof, void *data)
+{
+       struct obd_device *obd = data;
+       struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
+
+       if (osp == NULL || osp->opd_pre == NULL)
+               return 0;
+
+       return snprintf(page, count, LPX64"\n",
+                       fid_seq(&osp->opd_pre_used_fid));
+}
+
+static int osp_rd_prealloc_last_seq(char *page, char **start, off_t off,
+                                   int count, int *eof, void *data)
+{
+       struct obd_device *obd = data;
+       struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
+
+       if (osp == NULL || osp->opd_pre == NULL)
                return 0;
 
-       return snprintf(page, count, LPU64"\n", osp->opd_pre_last_created);
+       return snprintf(page, count, LPX64"\n",
+                       fid_seq(&osp->opd_pre_last_created_fid));
 }
 
 static int osp_rd_prealloc_reserved(char *page, char **start, off_t off,
@@ -312,7 +340,7 @@ static int osp_rd_prealloc_reserved(char *page, char **start, off_t off,
        struct obd_device *obd = data;
        struct osp_device *osp = lu2osp_dev(obd->obd_lu_dev);
 
-       if (osp == NULL)
+       if (osp == NULL || osp->opd_pre == NULL)
                return 0;
 
        return snprintf(page, count, LPU64"\n", osp->opd_pre_reserved);
@@ -361,7 +389,7 @@ static int osp_rd_pre_status(char *page, char **start, off_t off,
        struct osp_device       *osp = lu2osp_dev(dev->obd_lu_dev);
        int                      rc;
 
-       if (osp == NULL)
+       if (osp == NULL || osp->opd_pre == NULL)
                return -EINVAL;
 
        rc = snprintf(page, count, "%d\n", osp->opd_pre_status);
@@ -374,6 +402,9 @@ static int osp_rd_destroys_in_flight(char *page, char **start, off_t off,
        struct obd_device *dev = data;
        struct osp_device *osp = lu2osp_dev(dev->obd_lu_dev);
 
+       if (osp == NULL)
+               return -EINVAL;
+
        /*
         * This counter used to determine if OST has space returned.
         * Now we need to wait for the following:
@@ -402,12 +433,6 @@ static struct lprocfs_vars lprocfs_osp_obd_vars[] = {
        { "uuid",               lprocfs_rd_uuid, 0, 0 },
        { "ping",               0, lprocfs_wr_ping, 0, 0, 0222 },
        { "connect_flags",      lprocfs_rd_connect_flags, 0, 0 },
-       { "blocksize",          lprocfs_rd_blksize, 0, 0 },
-       { "kbytestotal",        lprocfs_rd_kbytestotal, 0, 0 },
-       { "kbytesfree",         lprocfs_rd_kbytesfree, 0, 0 },
-       { "kbytesavail",        lprocfs_rd_kbytesavail, 0, 0 },
-       { "filestotal",         lprocfs_rd_filestotal, 0, 0 },
-       { "filesfree",          lprocfs_rd_filesfree, 0, 0 },
        { "ost_server_uuid",    lprocfs_rd_server_uuid, 0, 0 },
        { "ost_conn_uuid",      lprocfs_rd_conn_uuid, 0, 0 },
        { "active",             osp_rd_active, osp_wr_active, 0 },
@@ -420,7 +445,9 @@ static struct lprocfs_vars lprocfs_osp_obd_vars[] = {
        { "max_create_count",   osp_rd_max_create_count,
                                osp_wr_max_create_count, 0 },
        { "prealloc_next_id",   osp_rd_prealloc_next_id, 0, 0 },
-       { "prealloc_last_id",   osp_rd_prealloc_last_id, 0, 0 },
+       { "prealloc_next_seq",  osp_rd_prealloc_next_seq, 0, 0 },
+       { "prealloc_last_id",   osp_rd_prealloc_last_id,  0, 0 },
+       { "prealloc_last_seq",  osp_rd_prealloc_last_seq, 0, 0 },
        { "prealloc_reserved",  osp_rd_prealloc_reserved, 0, 0 },
        { "timeouts",           lprocfs_rd_timeouts, 0, 0 },
        { "import",             lprocfs_rd_import, lprocfs_wr_import, 0 },
@@ -437,6 +464,16 @@ static struct lprocfs_vars lprocfs_osp_obd_vars[] = {
        { 0 }
 };
 
+static struct lprocfs_vars lprocfs_osp_osd_vars[] = {
+       { "blocksize",          lprocfs_dt_rd_blksize, 0, 0 },
+       { "kbytestotal",        lprocfs_dt_rd_kbytestotal, 0, 0 },
+       { "kbytesfree",         lprocfs_dt_rd_kbytesfree, 0, 0 },
+       { "kbytesavail",        lprocfs_dt_rd_kbytesavail, 0, 0 },
+       { "filestotal",         lprocfs_dt_rd_filestotal, 0, 0 },
+       { "filesfree",          lprocfs_dt_rd_filesfree, 0, 0 },
+       { 0 }
+};
+
 static struct lprocfs_vars lprocfs_osp_module_vars[] = {
        { "num_refs",           lprocfs_rd_numrefs, 0, 0 },
        { 0 }
@@ -447,5 +484,54 @@ void lprocfs_osp_init_vars(struct lprocfs_static_vars *lvars)
        lvars->module_vars = lprocfs_osp_module_vars;
        lvars->obd_vars = lprocfs_osp_obd_vars;
 }
+
+void osp_lprocfs_init(struct osp_device *osp)
+{
+       struct obd_device       *obd = osp->opd_obd;
+       struct proc_dir_entry   *osc_proc_dir;
+       int                      rc;
+
+       obd->obd_proc_entry = lprocfs_register(obd->obd_name,
+                                              obd->obd_type->typ_procroot,
+                                              lprocfs_osp_osd_vars,
+                                              &osp->opd_dt_dev);
+       if (IS_ERR(obd->obd_proc_entry)) {
+               CERROR("%s: can't register in lprocfs: %ld\n",
+                      obd->obd_name, PTR_ERR(obd->obd_proc_entry));
+               obd->obd_proc_entry = NULL;
+               return;
+       }
+
+       rc = lprocfs_add_vars(obd->obd_proc_entry, lprocfs_osp_obd_vars, obd);
+       if (rc) {
+               CERROR("%s: can't register in lprocfs: %ld\n",
+                      obd->obd_name, PTR_ERR(obd->obd_proc_entry));
+               return;
+       }
+
+       ptlrpc_lprocfs_register_obd(obd);
+
+       /* for compatibility we link old procfs's OSC entries to osp ones */
+       if (!osp->opd_connect_mdt) {
+               osc_proc_dir = lprocfs_srch(proc_lustre_root, "osc");
+               if (osc_proc_dir) {
+                       cfs_proc_dir_entry_t    *symlink = NULL;
+                       char                    *name;
+
+                       OBD_ALLOC(name, strlen(obd->obd_name) + 1);
+                       if (name == NULL)
+                               return;
+
+                       strcpy(name, obd->obd_name);
+                       if (strstr(name, "osc"))
+                               symlink = lprocfs_add_symlink(name,
+                                               osc_proc_dir, "../osp/%s",
+                                               obd->obd_name);
+                       OBD_FREE(name, strlen(obd->obd_name) + 1);
+                       osp->opd_symlink = symlink;
+               }
+       }
+}
+
 #endif /* LPROCFS */