Whamcloud - gitweb
LU-1399 config: check lustre_cfg_new() return
[fs/lustre-release.git] / lustre / lod / lproc_lod.c
index 1598658..f748010 100644 (file)
 #include "lod_internal.h"
 #include <lustre_param.h>
 
+/*
+ * Notice, all the functions below (except for lod_procfs_init() and
+ * lod_procfs_fini()) are not supposed to be used directly. They are
+ * called by Linux kernel's procfs.
+ */
+
 #ifdef LPROCFS
+
+/**
+ * Show default stripe size.
+ *
+ * \param[in] m                seq file
+ * \param[in] v                unused for single entry
+ *
+ * \retval 0           on success
+ * \retval negative    error code if failed
+ */
 static int lod_stripesize_seq_show(struct seq_file *m, void *v)
 {
        struct obd_device *dev = m->private;
@@ -53,6 +69,19 @@ static int lod_stripesize_seq_show(struct seq_file *m, void *v)
                        lod->lod_desc.ld_default_stripe_size);
 }
 
+/**
+ * Set default stripe size.
+ *
+ * \param[in] file     proc file
+ * \param[in] buffer   string containing the maximum number of bytes stored in
+ *                     each object before moving to the next object in the
+ *                     layout (if any)
+ * \param[in] count    @buffer length
+ * \param[in] off      unused for single entry
+ *
+ * \retval @count      on success
+ * \retval negative    error code if failed
+ */
 static ssize_t
 lod_stripesize_seq_write(struct file *file, const char *buffer,
                         size_t count, loff_t *off)
@@ -75,6 +104,15 @@ lod_stripesize_seq_write(struct file *file, const char *buffer,
 }
 LPROC_SEQ_FOPS(lod_stripesize);
 
+/**
+ * Show default stripe offset.
+ *
+ * \param[in] m                seq file
+ * \param[in] v                unused for single entry
+ *
+ * \retval 0           on success
+ * \retval negative    error code if failed
+ */
 static int lod_stripeoffset_seq_show(struct seq_file *m, void *v)
 {
        struct obd_device *dev = m->private;
@@ -86,6 +124,20 @@ static int lod_stripeoffset_seq_show(struct seq_file *m, void *v)
                        lod->lod_desc.ld_default_stripe_offset);
 }
 
+/**
+ * Set default stripe offset.
+ *
+ * Usually contains -1 allowing Lustre to balance objects among OST
+ * otherwise may cause severe OST imbalance.
+ *
+ * \param[in] file     proc file
+ * \param[in] buffer   string describing starting OST index for new files
+ * \param[in] count    @buffer length
+ * \param[in] off      unused for single entry
+ *
+ * \retval @count      on success
+ * \retval negative    error code if failed
+ */
 static ssize_t
 lod_stripeoffset_seq_write(struct file *file, const char *buffer,
                           size_t count, loff_t *off)
@@ -107,6 +159,15 @@ lod_stripeoffset_seq_write(struct file *file, const char *buffer,
 }
 LPROC_SEQ_FOPS(lod_stripeoffset);
 
+/**
+ * Show default striping pattern (LOV_PATTERN_*).
+ *
+ * \param[in] m                seq file
+ * \param[in] v                unused for single entry
+ *
+ * \retval 0           on success
+ * \retval negative    error code if failed
+ */
 static int lod_stripetype_seq_show(struct seq_file *m, void *v)
 {
        struct obd_device *dev = m->private;
@@ -117,6 +178,18 @@ static int lod_stripetype_seq_show(struct seq_file *m, void *v)
        return seq_printf(m, "%u\n", lod->lod_desc.ld_pattern);
 }
 
+/**
+ * Set default striping pattern (a number, not a human-readable string).
+ *
+ * \param[in] file     proc file
+ * \param[in] buffer   string containing the default striping pattern for new
+ *                     files. This is an integer LOV_PATTERN_* value
+ * \param[in] count    @buffer length
+ * \param[in] off      unused for single entry
+ *
+ * \retval @count      on success
+ * \retval negative    error code if failed
+ */
 static ssize_t
 lod_stripetype_seq_write(struct file *file, const char *buffer,
                         size_t count, loff_t *off)
@@ -138,6 +211,15 @@ lod_stripetype_seq_write(struct file *file, const char *buffer,
 }
 LPROC_SEQ_FOPS(lod_stripetype);
 
+/**
+ * Show default number of stripes.
+ *
+ * \param[in] m                seq file
+ * \param[in] v                unused for single entry
+ *
+ * \retval 0           on success,
+ * \retval negative    error code if failed
+ */
 static int lod_stripecount_seq_show(struct seq_file *m, void *v)
 {
        struct obd_device *dev = m->private;
@@ -149,6 +231,18 @@ static int lod_stripecount_seq_show(struct seq_file *m, void *v)
                        (__s16)(lod->lod_desc.ld_default_stripe_count + 1) - 1);
 }
 
+/**
+ * Set default number of stripes.
+ *
+ * \param[in] file     proc file
+ * \param[in] buffer   string containing the default number of stripes
+ *                     for new files
+ * \param[in] count    @buffer length
+ * \param[in] off      unused for single entry
+ *
+ * \retval @count      on success
+ * \retval negative    error code otherwise
+ */
 static ssize_t
 lod_stripecount_seq_write(struct file *file, const char *buffer,
                          size_t count, loff_t *off)
@@ -170,6 +264,15 @@ lod_stripecount_seq_write(struct file *file, const char *buffer,
 }
 LPROC_SEQ_FOPS(lod_stripecount);
 
+/**
+ * Show number of targets.
+ *
+ * \param[in] m                seq file
+ * \param[in] v                unused for single entry
+ *
+ * \retval 0           on success
+ * \retval negative    error code if failed
+ */
 static int lod_numobd_seq_show(struct seq_file *m, void *v)
 {
        struct obd_device *dev = m->private;
@@ -181,6 +284,15 @@ static int lod_numobd_seq_show(struct seq_file *m, void *v)
 }
 LPROC_SEQ_FOPS_RO(lod_numobd);
 
+/**
+ * Show number of active targets.
+ *
+ * \param[in] m                seq file
+ * \param[in] v                unused for single entry
+ *
+ * \retval 0           on success
+ * \retval negative    error code if failed
+ */
 static int lod_activeobd_seq_show(struct seq_file *m, void *v)
 {
        struct obd_device *dev = m->private;
@@ -192,6 +304,15 @@ static int lod_activeobd_seq_show(struct seq_file *m, void *v)
 }
 LPROC_SEQ_FOPS_RO(lod_activeobd);
 
+/**
+ * Show UUID of LOD device.
+ *
+ * \param[in] m                seq file
+ * \param[in] v                unused for single entry
+ *
+ * \retval 0           on success
+ * \retval negative    error code if failed
+ */
 static int lod_desc_uuid_seq_show(struct seq_file *m, void *v)
 {
        struct obd_device *dev = m->private;
@@ -203,7 +324,20 @@ static int lod_desc_uuid_seq_show(struct seq_file *m, void *v)
 }
 LPROC_SEQ_FOPS_RO(lod_desc_uuid);
 
-/* free priority (0-255): how badly user wants to choose empty osts */
+/**
+ * Show QoS priority parameter.
+ *
+ * The printed value is a percentage value (0-100%) indicating the priority
+ * of free space compared to performance. 0% means select OSTs equally
+ * regardless of their free space, 100% means select OSTs only by their free
+ * space even if it results in very imbalanced load on the OSTs.
+ *
+ * \param[in] m                seq file
+ * \param[in] v                unused for single entry
+ *
+ * \retval 0           on success
+ * \retval negative    error code if failed
+ */
 static int lod_qos_priofree_seq_show(struct seq_file *m, void *v)
 {
        struct obd_device *dev = m->private;
@@ -214,8 +348,24 @@ static int lod_qos_priofree_seq_show(struct seq_file *m, void *v)
                        (lod->lod_qos.lq_prio_free * 100 + 255) >> 8);
 }
 
+/**
+ * Set QoS free space priority parameter.
+ *
+ * Set the relative priority of free OST space compared to OST load when OSTs
+ * are space imbalanced.  See lod_qos_priofree_seq_show() for description of
+ * this parameter.  See lod_qos_thresholdrr_seq_write() and lq_threshold_rr to
+ * determine what constitutes "space imbalanced" OSTs.
+ *
+ * \param[in] file     proc file
+ * \param[in] buffer   string which contains the free space priority (0-100)
+ * \param[in] count    @buffer length
+ * \param[in] off      unused for single entry
+ *
+ * \retval @count      on success
+ * \retval negative    error code if failed
+ */
 static ssize_t
-lod_qos_priofree_seq_write(struct file *file, const char *buffer,
+lod_qos_priofree_seq_write(struct file *file, const char __user *buffer,
                           size_t count, loff_t *off)
 {
        struct seq_file   *m = file->private_data;
@@ -239,6 +389,15 @@ lod_qos_priofree_seq_write(struct file *file, const char *buffer,
 }
 LPROC_SEQ_FOPS(lod_qos_priofree);
 
+/**
+ * Show threshold for "same space on all OSTs" rule.
+ *
+ * \param[in] m                seq file
+ * \param[in] v                unused for single entry
+ *
+ * \retval 0           on success
+ * \retval negative    error code if failed
+ */
 static int lod_qos_thresholdrr_seq_show(struct seq_file *m, void *v)
 {
        struct obd_device *dev = m->private;
@@ -250,6 +409,23 @@ static int lod_qos_thresholdrr_seq_show(struct seq_file *m, void *v)
                        (lod->lod_qos.lq_threshold_rr * 100 + 255) >> 8);
 }
 
+/**
+ * Set threshold for "same space on all OSTs" rule.
+ *
+ * This sets the maximum percentage difference of free space between the most
+ * full and most empty OST in the currently available OSTs. If this percentage
+ * is exceeded, use the QoS allocator to select OSTs based on their available
+ * space so that more full OSTs are chosen less often, otherwise use the
+ * round-robin allocator for efficiency and performance.
+
+ * \param[in] file     proc file
+ * \param[in] buffer   string containing percentage difference of free space
+ * \param[in] count    @buffer length
+ * \param[in] off      unused for single entry
+ *
+ * \retval @count      on success
+ * \retval negative    error code if failed
+ */
 static ssize_t
 lod_qos_thresholdrr_seq_write(struct file *file, const char *buffer,
                              size_t count, loff_t *off)
@@ -275,6 +451,16 @@ lod_qos_thresholdrr_seq_write(struct file *file, const char *buffer,
 }
 LPROC_SEQ_FOPS(lod_qos_thresholdrr);
 
+/**
+ * Show expiration period used to refresh cached statfs data, which
+ * is used to implement QoS/RR striping allocation algorithm.
+ *
+ * \param[in] m                seq file
+ * \param[in] v                unused for single entry
+ *
+ * \retval 0           on success
+ * \retval negative    error code if failed
+ */
 static int lod_qos_maxage_seq_show(struct seq_file *m, void *v)
 {
        struct obd_device *dev = m->private;
@@ -285,6 +471,17 @@ static int lod_qos_maxage_seq_show(struct seq_file *m, void *v)
        return seq_printf(m, "%u Sec\n", lod->lod_desc.ld_qos_maxage);
 }
 
+/**
+ * Set expiration period used to refresh cached statfs data.
+ *
+ * \param[in] file     proc file
+ * \param[in] buffer   string contains maximum age of statfs data in seconds
+ * \param[in] count    @buffer length
+ * \param[in] off      unused for single entry
+ *
+ * \retval @count      on success
+ * \retval negative    error code if failed
+ */
 static ssize_t
 lod_qos_maxage_seq_write(struct file *file, const char *buffer,
                         size_t count, loff_t *off)
@@ -296,7 +493,8 @@ lod_qos_maxage_seq_write(struct file *file, const char *buffer,
        struct lu_device        *next;
        struct lustre_cfg       *lcfg;
        char                     str[32];
-       int                      val, rc, i;
+       unsigned int             i;
+       int                      val, rc;
 
        LASSERT(dev != NULL);
        lod = lu2lod_dev(dev->obd_lu_dev);
@@ -316,6 +514,9 @@ lod_qos_maxage_seq_write(struct file *file, const char *buffer,
        sprintf(str, "%smaxage=%d", PARAM_OSP, val);
        lustre_cfg_bufs_set_string(&bufs, 1, str);
        lcfg = lustre_cfg_new(LCFG_PARAM, &bufs);
+       if (lcfg == NULL)
+               return -ENOMEM;
+
        lod_getref(&lod->lod_ost_descs);
        lod_foreach_ost(lod, i) {
                next = &OST_TGT(lod,i)->ltd_ost->dd_lu_dev;
@@ -376,6 +577,15 @@ static void *lod_osts_seq_next(struct seq_file *p, void *v, loff_t *pos)
                return NULL;
 }
 
+/**
+ * Show active/inactive status for OST found by lod_osts_seq_next().
+ *
+ * \param[in] m                seq file
+ * \param[in] v                unused for single entry
+ *
+ * \retval 0           on success
+ * \retval negative    error code if failed
+ */
 static int lod_osts_seq_show(struct seq_file *p, void *v)
 {
        struct obd_device   *obd = p->private;
@@ -437,6 +647,67 @@ LPROC_SEQ_FOPS_RO_TYPE(lod, dt_kbytesavail);
 LPROC_SEQ_FOPS_RO_TYPE(lod, dt_filestotal);
 LPROC_SEQ_FOPS_RO_TYPE(lod, dt_filesfree);
 
+/**
+ * Show whether special failout mode for testing is enabled or not.
+ *
+ * \param[in] m                seq file
+ * \param[in] v                unused for single entry
+ *
+ * \retval 0           on success
+ * \retval negative    error code if failed
+ */
+static int lod_lmv_failout_seq_show(struct seq_file *m, void *v)
+{
+       struct obd_device *dev = m->private;
+       struct lod_device *lod;
+
+       LASSERT(dev != NULL);
+       lod = lu2lod_dev(dev->obd_lu_dev);
+
+       return seq_printf(m, "%d\n", lod->lod_lmv_failout ? 1 : 0);
+}
+
+/**
+ * Enable/disable a special failout mode for testing.
+ *
+ * This determines whether the LMV will try to continue processing a striped
+ * directory even if it has a (partly) corrupted entry in the master directory,
+ * or if it will abort upon finding a corrupted slave directory entry.
+ *
+ * \param[in] file     proc file
+ * \param[in] buffer   string: 0 or non-zero to disable or enable LMV failout
+ * \param[in] count    @buffer length
+ * \param[in] off      unused for single entry
+ *
+ * \retval @count      on success
+ * \retval negative    error code if failed
+ */
+static ssize_t
+lod_lmv_failout_seq_write(struct file *file, const char *buffer,
+                         size_t count, loff_t *off)
+{
+       struct seq_file         *m      = file->private_data;
+       struct obd_device       *dev    = m->private;
+       struct lod_device       *lod;
+       int                      val    = 0;
+       int                      rc;
+
+       LASSERT(dev != NULL);
+       lod = lu2lod_dev(dev->obd_lu_dev);
+
+       rc = lprocfs_write_helper(buffer, count, &val);
+       if (rc != 0)
+               return rc;
+
+       if (val != 0)
+               lod->lod_lmv_failout = 1;
+       else
+               lod->lod_lmv_failout = 0;
+
+       return count;
+}
+LPROC_SEQ_FOPS(lod_lmv_failout);
+
 static struct lprocfs_seq_vars lprocfs_lod_obd_vars[] = {
        { .name =       "uuid",
          .fops =       &lod_uuid_fops          },
@@ -460,6 +731,8 @@ static struct lprocfs_seq_vars lprocfs_lod_obd_vars[] = {
          .fops =       &lod_qos_thresholdrr_fops },
        { .name =       "qos_maxage",
          .fops =       &lod_qos_maxage_fops    },
+       { .name =       "lmv_failout",
+         .fops =       &lod_lmv_failout_fops   },
        { 0 }
 };
 
@@ -481,6 +754,14 @@ static const struct file_operations lod_proc_target_fops = {
        .release = lprocfs_seq_release,
 };
 
+/**
+ * Initialize procfs entries for LOD.
+ *
+ * \param[in] lod      LOD device
+ *
+ * \retval 0           on success
+ * \retval negative    error code if failed
+ */
 int lod_procfs_init(struct lod_device *lod)
 {
        struct obd_device       *obd = lod2obd(lod);
@@ -489,7 +770,7 @@ int lod_procfs_init(struct lod_device *lod)
        int                      rc;
 
        obd->obd_vars = lprocfs_lod_obd_vars;
-       rc = lprocfs_seq_obd_setup(obd);
+       rc = lprocfs_obd_setup(obd);
        if (rc) {
                CERROR("%s: cannot setup procfs entry: %d\n",
                       obd->obd_name, rc);
@@ -539,8 +820,8 @@ int lod_procfs_init(struct lod_device *lod)
        lod->lod_symlink = lprocfs_add_symlink(obd->obd_name, lov_proc_dir,
                                               "../lod/%s", obd->obd_name);
        if (lod->lod_symlink == NULL)
-               CERROR("could not register LOV symlink for "
-                       "/proc/fs/lustre/lod/%s.", obd->obd_name);
+               CERROR("cannot create LOV symlink for /proc/fs/lustre/lod/%s\n",
+                      obd->obd_name);
        RETURN(0);
 
 out:
@@ -549,6 +830,11 @@ out:
        return rc;
 }
 
+/**
+ * Cleanup procfs entries registred for LOD.
+ *
+ * \param[in] lod      LOD device
+ */
 void lod_procfs_fini(struct lod_device *lod)
 {
        struct obd_device *obd = lod2obd(lod);