Whamcloud - gitweb
- commit from zzeng
[fs/lustre-release.git] / lustre / llite / lproc_llite.c
index 86e37e8..665e9d7 100644 (file)
 #include <linux/lustre_lite.h>
 #include <linux/lprocfs_status.h>
 #include <linux/seq_file.h>
+#include <linux/obd_support.h>
 
 #include "llite_internal.h"
 
 /* /proc/lustre/llite mount point registration */
 struct proc_dir_entry *proc_lustre_fs_root;
 struct file_operations llite_dump_pgcache_fops;
+struct file_operations ll_ra_stats_fops;
+struct file_operations llite_wait_times_fops;
+
 
 #ifndef LPROCFS
 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
@@ -105,6 +109,28 @@ static int ll_rd_kbytesfree(char *page, char **start, off_t off, int count,
         return rc;
 }
 
+static int ll_rd_kbytesavail(char *page, char **start, off_t off, int count,
+                             int *eof, void *data)
+{
+        struct super_block *sb = (struct super_block *)data;
+        struct obd_statfs osfs;
+        int rc;
+
+        LASSERT(sb != NULL);
+        rc = ll_statfs_internal(sb, &osfs, jiffies - HZ);
+        if (!rc) {
+                __u32 blk_size = osfs.os_bsize >> 10;
+                __u64 result = osfs.os_bavail;
+
+                while (blk_size >>= 1)
+                        result <<= 1;
+
+                *eof = 1;
+                rc = snprintf(page, count, LPU64"\n", result);
+        }
+        return rc;
+}
+
 static int ll_rd_filestotal(char *page, char **start, off_t off, int count,
                             int *eof, void *data)
 {
@@ -138,14 +164,6 @@ static int ll_rd_filesfree(char *page, char **start, off_t off, int count,
 
 }
 
-#if 0
-static int ll_rd_path(char *page, char **start, off_t off, int count, int *eof,
-                      void *data)
-{
-        return 0;
-}
-#endif
-
 static int ll_rd_fstype(char *page, char **start, off_t off, int count,
                         int *eof, void *data)
 {
@@ -187,9 +205,9 @@ static int ll_wr_read_ahead(struct file *file, const char *buffer,
         struct ll_sb_info *sbi = ll_s2sbi(sb);
         int readahead;
         ENTRY;
-
-        if (1 != sscanf(buffer, "%d", &readahead))
-                RETURN(-EINVAL);        
+        
+        if (sscanf(buffer, "%d", &readahead) != 1)
+                RETURN(-EINVAL);
 
         if (readahead)
                 sbi->ll_flags |= LL_SBI_READAHEAD;
@@ -199,6 +217,52 @@ static int ll_wr_read_ahead(struct file *file, const char *buffer,
         RETURN(count);
 }
 
+static int ll_wr_config_update(struct file *file, const char *buffer,
+                               unsigned long count, void *data)
+{
+        struct super_block *sb = (struct super_block*)data;
+        struct ll_sb_info *sbi = ll_s2sbi(sb);
+        ENTRY;
+
+        CWARN("Starting a LOV/OST update !\n");
+        RETURN(ll_process_config_update(sbi, 0));
+}
+
+static int ll_rd_max_read_ahead_mb(char *page, char **start, off_t off,
+                                   int count, int *eof, void *data)
+{
+        struct super_block *sb = data;
+        struct ll_sb_info *sbi = ll_s2sbi(sb);
+        unsigned val;
+
+        spin_lock(&sbi->ll_lock);
+        val = (sbi->ll_ra_info.ra_max_pages << PAGE_CACHE_SHIFT) >> 20;
+        spin_unlock(&sbi->ll_lock);
+
+        return snprintf(page, count, "%u\n", val);
+}
+
+static int ll_wr_max_read_ahead_mb(struct file *file, const char *buffer,
+                                   unsigned long count, void *data)
+{
+        struct super_block *sb = data;
+        struct ll_sb_info *sbi = ll_s2sbi(sb);
+        int val, rc;
+
+        rc = lprocfs_write_helper(buffer, count, &val);
+        if (rc)
+                return rc;
+
+        if (val < 0 || val > (num_physpages << PAGE_SHIFT) >> 20)
+                return -ERANGE;
+
+        spin_lock(&sbi->ll_lock);
+        sbi->ll_ra_info.ra_max_pages = (val << 20) >> PAGE_CACHE_SHIFT;
+        spin_unlock(&sbi->ll_lock);
+
+        return count;
+}
+
 static struct lprocfs_vars lprocfs_obd_vars[] = {
         { "uuid",         ll_rd_sb_uuid,          0, 0 },
         //{ "mntpt_path",   ll_rd_path,             0, 0 },
@@ -206,10 +270,14 @@ static struct lprocfs_vars lprocfs_obd_vars[] = {
         { "blocksize",    ll_rd_blksize,          0, 0 },
         { "kbytestotal",  ll_rd_kbytestotal,      0, 0 },
         { "kbytesfree",   ll_rd_kbytesfree,       0, 0 },
+        { "kbytesavail",  ll_rd_kbytesavail,      0, 0 },
         { "filestotal",   ll_rd_filestotal,       0, 0 },
         { "filesfree",    ll_rd_filesfree,        0, 0 },
         //{ "filegroups",   lprocfs_rd_filegroups,  0, 0 },
         { "read_ahead",   ll_rd_read_ahead, ll_wr_read_ahead, 0 },
+        { "config_update", 0, ll_wr_config_update, 0 },
+        { "max_read_ahead_mb", ll_rd_max_read_ahead_mb,
+                               ll_wr_max_read_ahead_mb, 0 },
         { 0 }
 };
 
@@ -273,6 +341,7 @@ int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
         char name[MAX_STRING_SIZE + 1];
         int err, id;
         struct lprocfs_stats *svc_stats = NULL;
+        struct proc_dir_entry *mdc_symlink, *osc_symlink;
         struct proc_dir_entry *entry;
         ENTRY;
 
@@ -298,10 +367,22 @@ int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
 
         entry = create_proc_entry("dump_page_cache", 0444, sbi->ll_proc_root);
         if (entry == NULL)
-                GOTO(out, -ENOMEM);
+                GOTO(out, err = -ENOMEM);
         entry->proc_fops = &llite_dump_pgcache_fops;
         entry->data = sbi;
 
+        entry = create_proc_entry("wait_times", 0444, sbi->ll_proc_root);
+        if (entry == NULL)
+                GOTO(out, err = -ENOMEM);
+        entry->proc_fops = &llite_wait_times_fops;
+        entry->data = sbi;
+
+        entry = create_proc_entry("read_ahead_stats", 0444, sbi->ll_proc_root);
+        if (entry == NULL)
+                GOTO(out, err = -ENOMEM);
+        entry->proc_fops = &ll_ra_stats_fops;
+        entry->data = sbi;
+
         svc_stats = lprocfs_alloc_stats(LPROC_LL_FILE_OPCODES);
         if (svc_stats == NULL) {
                 err = -ENOMEM;
@@ -344,18 +425,14 @@ int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
         LASSERT(obd->obd_type != NULL);
         LASSERT(obd->obd_type->typ_name != NULL);
 
-        snprintf(name, MAX_STRING_SIZE, "%s/common_name",
-                 obd->obd_type->typ_name);
-        lvars[0].read_fptr = lprocfs_rd_name;
-        err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
-        if (err)
-                goto out;
-
-        snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
-        lvars[0].read_fptr = lprocfs_rd_uuid;
-        err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
-        if (err)
+        snprintf(name, MAX_STRING_SIZE, "../../%s/%s",
+                 obd->obd_type->typ_name, obd->obd_name);
+        mdc_symlink = proc_symlink(obd->obd_type->typ_name, sbi->ll_proc_root,
+                                   name);
+        if (mdc_symlink == NULL) {
+                err = -ENOMEM;
                 goto out;
+        }
 
         /* OSC */
         obd = class_name2obd(osc);
@@ -364,16 +441,14 @@ int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
         LASSERT(obd->obd_type != NULL);
         LASSERT(obd->obd_type->typ_name != NULL);
 
-        snprintf(name, MAX_STRING_SIZE, "%s/common_name",
-                 obd->obd_type->typ_name);
-        lvars[0].read_fptr = lprocfs_rd_name;
-        err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
-        if (err)
-                goto out;
+       snprintf(name, MAX_STRING_SIZE, "../../%s/%s",
+                obd->obd_type->typ_name, obd->obd_name);
+       osc_symlink = proc_symlink(obd->obd_type->typ_name, sbi->ll_proc_root,
+                                  name);
+       if (osc_symlink == NULL)
+               err = -ENOMEM;
+
 
-        snprintf(name, MAX_STRING_SIZE, "%s/uuid", obd->obd_type->typ_name);
-        lvars[0].read_fptr = lprocfs_rd_uuid;
-        err = lprocfs_add_vars(sbi->ll_proc_root, lvars, obd);
 out:
         if (err) {
                 if (svc_stats)
@@ -439,15 +514,15 @@ static int llite_dump_pgcache_seq_show(struct seq_file *seq, void *v)
                 return 0;
         }
 
-        spin_lock(&sbi->ll_pglist_lock);
+        spin_lock(&sbi->ll_lock);
 
         llap = llite_pglist_next_llap(sbi, &dummy_llap->llap_proc_item);
         if (llap != NULL)  {
                 int has_flags = 0;
                 struct page *page = llap->llap_page;
 
-                seq_printf(seq, "%lu | %p %p | %p %p %lu [", 
-                                sbi->ll_pglist_gen, 
+                seq_printf(seq, "%lu | %p %p | %p %p %lu [",
+                                sbi->ll_pglist_gen,
                                 llap, llap->llap_cookie,
                                 page, page->mapping->host, page->index);
                 seq_page_flag(seq, page, locked, has_flags);
@@ -458,11 +533,11 @@ static int llite_dump_pgcache_seq_show(struct seq_file *seq, void *v)
                 seq_page_flag(seq, page, highmem, has_flags);
                 if (!has_flags)
                         seq_puts(seq, "-]\n");
-                else 
+                else
                         seq_puts(seq, "]\n");
         }
 
-        spin_unlock(&sbi->ll_pglist_lock);
+        spin_unlock(&sbi->ll_lock);
 
         return 0;
 }
@@ -477,7 +552,7 @@ static void *llite_dump_pgcache_seq_start(struct seq_file *seq, loff_t *pos)
         return (void *)1;
 }
 
-static void *llite_dump_pgcache_seq_next(struct seq_file *seq, void *v, 
+static void *llite_dump_pgcache_seq_next(struct seq_file *seq, void *v,
                                          loff_t *pos)
 {
         struct ll_async_page *llap, *dummy_llap = seq->private;
@@ -492,14 +567,14 @@ static void *llite_dump_pgcache_seq_next(struct seq_file *seq, void *v,
         /* we've just displayed the llap that is after us in the list.
          * we advance to a position beyond it, returning null if there
          * isn't another llap in the list beyond that new position. */
-        spin_lock(&sbi->ll_pglist_lock);
+        spin_lock(&sbi->ll_lock);
         llap = llite_pglist_next_llap(sbi, &dummy_llap->llap_proc_item);
         list_del_init(&dummy_llap->llap_proc_item);
         if (llap) {
                 list_add(&dummy_llap->llap_proc_item, &llap->llap_proc_item);
                 llap = llite_pglist_next_llap(sbi, &dummy_llap->llap_proc_item);
         }
-        spin_unlock(&sbi->ll_pglist_lock);
+        spin_unlock(&sbi->ll_lock);
 
         ++*pos;
         if (llap == NULL) {
@@ -533,54 +608,253 @@ struct seq_operations llite_dump_pgcache_seq_sops = {
  */
 static int llite_dump_pgcache_seq_open(struct inode *inode, struct file *file)
 {
-        struct proc_dir_entry *dp = inode->u.generic_ip;
+        struct proc_dir_entry *dp = PDE(inode);
         struct ll_async_page *llap;
         struct seq_file *seq;
         struct ll_sb_info *sbi = dp->data;
         int rc;
 
-        llap = kmalloc(sizeof(*llap), GFP_KERNEL);
+        OBD_ALLOC_GFP(llap, sizeof(*llap), GFP_KERNEL);
         if (llap == NULL)
                 return -ENOMEM;
         llap->llap_page = NULL;
         llap->llap_cookie = sbi;
         llap->llap_magic = 0;
+
         rc = seq_open(file, &llite_dump_pgcache_seq_sops);
         if (rc) {
-                kfree(llap);
+                OBD_FREE(llap, sizeof(*llap));
                 return rc;
         }
         seq = file->private_data;
         seq->private = llap;
 
-        spin_lock(&sbi->ll_pglist_lock);
+        spin_lock(&sbi->ll_lock);
         list_add(&llap->llap_proc_item, &sbi->ll_pglist);
-        spin_unlock(&sbi->ll_pglist_lock);
+        spin_unlock(&sbi->ll_lock);
 
         return 0;
 }
 
-static int llite_dump_pgcache_seq_release(struct inode *inode, 
+static int llite_dump_pgcache_seq_release(struct inode *inode,
                                           struct file *file)
 {
         struct seq_file *seq = file->private_data;
         struct ll_async_page *llap = seq->private;
         struct ll_sb_info *sbi = llap->llap_cookie;
 
-        spin_lock(&sbi->ll_pglist_lock);
+        spin_lock(&sbi->ll_lock);
         if (!list_empty(&llap->llap_proc_item))
                 list_del_init(&llap->llap_proc_item);
-        spin_unlock(&sbi->ll_pglist_lock);
-        kfree(llap);
+        spin_unlock(&sbi->ll_lock);
+        OBD_FREE(llap, sizeof(*llap));
 
         return seq_release(inode, file);
 }
 
 struct file_operations llite_dump_pgcache_fops = {
+        .owner   = THIS_MODULE,
         .open    = llite_dump_pgcache_seq_open,
         .read    = seq_read,
-        .release    = llite_dump_pgcache_seq_release,
+        .release = llite_dump_pgcache_seq_release,
+};
+static int ll_ra_stats_seq_show(struct seq_file *seq, void *v)
+{
+        struct timeval now;
+        struct ll_sb_info *sbi = seq->private;
+        struct ll_ra_info *ra = &sbi->ll_ra_info;
+        int i;
+        static char *ra_stat_strings[] = {
+                [RA_STAT_HIT] = "hits",
+                [RA_STAT_MISS] = "misses",
+                [RA_STAT_DISTANT_READPAGE] = "readpage not consecutive",
+                [RA_STAT_MISS_IN_WINDOW] = "miss inside window",
+                [RA_STAT_FAILED_MATCH] = "failed lock match",
+                [RA_STAT_DISCARDED] = "read but discarded",
+                [RA_STAT_ZERO_LEN] = "zero length file",
+                [RA_STAT_ZERO_WINDOW] = "zero size window",
+                [RA_STAT_EOF] = "read-ahead to EOF",
+                [RA_STAT_MAX_IN_FLIGHT] = "hit max r-a issue",
+        };
+
+        do_gettimeofday(&now);
+
+        spin_lock(&sbi->ll_lock);
+
+        seq_printf(seq, "snapshot_time:         %lu:%lu (secs:usecs)\n",
+                   now.tv_sec, now.tv_usec);
+        seq_printf(seq, "pending issued pages:           %lu\n",
+                   ra->ra_cur_pages);
+
+        for(i = 0; i < _NR_RA_STAT; i++)
+                seq_printf(seq, "%-25s %lu\n", ra_stat_strings[i],
+                           ra->ra_stats[i]);
+
+        spin_unlock(&sbi->ll_lock);
+
+        return 0;
+}
+
+static void *ll_ra_stats_seq_start(struct seq_file *p, loff_t *pos)
+{
+        if (*pos == 0)
+                return (void *)1;
+        return NULL;
+}
+static void *ll_ra_stats_seq_next(struct seq_file *p, void *v, loff_t *pos)
+{
+        ++*pos;
+        return NULL;
+}
+static void ll_ra_stats_seq_stop(struct seq_file *p, void *v)
+{
+}
+struct seq_operations ll_ra_stats_seq_sops = {
+        .start = ll_ra_stats_seq_start,
+        .stop = ll_ra_stats_seq_stop,
+        .next = ll_ra_stats_seq_next,
+        .show = ll_ra_stats_seq_show,
+};
+
+static int ll_ra_stats_seq_open(struct inode *inode, struct file *file)
+{
+        struct proc_dir_entry *dp = PDE(inode);
+        struct seq_file *seq;
+        int rc;
+
+        rc = seq_open(file, &ll_ra_stats_seq_sops);
+        if (rc)
+                return rc;
+        seq = file->private_data;
+        seq->private = dp->data;
+        return 0;
+}
+
+static ssize_t ll_ra_stats_seq_write(struct file *file, const char *buf,
+                                       size_t len, loff_t *off)
+{
+        struct seq_file *seq = file->private_data;
+        struct ll_sb_info *sbi = seq->private;
+        struct ll_ra_info *ra = &sbi->ll_ra_info;
+
+        spin_lock(&sbi->ll_lock);
+        memset(ra->ra_stats, 0, sizeof(ra->ra_stats));
+        spin_unlock(&sbi->ll_lock);
+
+        return len;
+}
+
+struct file_operations ll_ra_stats_fops = {
+        .owner   = THIS_MODULE,
+        .open    = ll_ra_stats_seq_open,
+        .read    = seq_read,
+        .write   = ll_ra_stats_seq_write,
+        .llseek  = seq_lseek,
+        .release = seq_release,
+};
+
+#define PRINTF_STIME(stime) (unsigned long)(stime)->st_num,     \
+        lprocfs_stime_avg_ms(stime), lprocfs_stime_avg_us(stime)
+
+static int llite_wait_times_seq_show(struct seq_file *seq, void *v)
+{
+        struct ll_sb_info *sbi = seq->private;
+        struct timeval now;
+
+        do_gettimeofday(&now);
+
+        spin_lock(&sbi->ll_lock);
+
+        seq_printf(seq, "snapshot_time:         %lu:%lu (secs:usecs)\n\n",
+                   now.tv_sec, now.tv_usec);
+
+        seq_printf(seq, "lock wait times: (num, average ms)\n");
+        seq_printf(seq, "\tread\t%lu\t%lu.%04lu\n",
+                        PRINTF_STIME(&sbi->ll_read_stime));
+        seq_printf(seq, "\twrite\t%lu\t%lu.%04lu\n",
+                        PRINTF_STIME(&sbi->ll_write_stime));
+        seq_printf(seq, "\tgroup\t%lu\t%lu.%04lu\n",
+                        PRINTF_STIME(&sbi->ll_grouplock_stime));
+        seq_printf(seq, "\tseek\t%lu\t%lu.%04lu\n",
+                        PRINTF_STIME(&sbi->ll_seek_stime));
+        seq_printf(seq, "\tsetattr\t%lu\t%lu.%04lu\n\n",
+                        PRINTF_STIME(&sbi->ll_setattr_stime));
+
+        seq_printf(seq, "io path wait times: (num, average ms)\n");
+        seq_printf(seq, "\tll_brw\t%lu\t%lu.%04lu\n",
+                        PRINTF_STIME(&sbi->ll_brw_stime));
+#if 0
+        seq_printf(seq, "\tdone\t%lu\t%lu.%04lu\n",
+                        PRINTF_STIME(&sbi->ll_done_stime));
+#endif
+
+        spin_unlock(&sbi->ll_lock);
+
+        return 0;
+}
+#undef pct
+
+static void *llite_wait_times_seq_start(struct seq_file *p, loff_t *pos)
+{
+        if (*pos == 0)
+                return (void *)1;
+        return NULL;
+}
+static void *llite_wait_times_seq_next(struct seq_file *p, void *v, loff_t *pos)
+{
+        ++*pos;
+        return NULL;
+}
+static void llite_wait_times_seq_stop(struct seq_file *p, void *v)
+{
+}
+struct seq_operations llite_wait_times_seq_sops = {
+        .start = llite_wait_times_seq_start,
+        .stop = llite_wait_times_seq_stop,
+        .next = llite_wait_times_seq_next,
+        .show = llite_wait_times_seq_show,
+};
+
+static int llite_wait_times_seq_open(struct inode *inode, struct file *file)
+{
+        struct proc_dir_entry *dp = PDE(inode);
+        struct seq_file *seq;
+        int rc;
+
+        rc = seq_open(file, &llite_wait_times_seq_sops);
+        if (rc)
+                return rc;
+        seq = file->private_data;
+        seq->private = dp->data;
+        return 0;
+}
+
+static ssize_t llite_wait_times_seq_write(struct file *file, const char *buf,
+                                       size_t len, loff_t *off)
+{
+        struct seq_file *seq = file->private_data;
+        struct ll_sb_info *sbi = seq->private;
+
+        spin_lock(&sbi->ll_lock);
+        memset(&sbi->ll_read_stime, 0, sizeof(sbi->ll_read_stime));
+        memset(&sbi->ll_write_stime, 0, sizeof(sbi->ll_write_stime));
+        memset(&sbi->ll_grouplock_stime, 0, sizeof(sbi->ll_grouplock_stime));
+        memset(&sbi->ll_seek_stime, 0, sizeof(sbi->ll_seek_stime));
+        memset(&sbi->ll_setattr_stime, 0, sizeof(sbi->ll_setattr_stime));
+        memset(&sbi->ll_brw_stime, 0, sizeof(sbi->ll_brw_stime));
+//        memset(&sbi->ll_done_stime, 0, sizeof(sbi->ll_done_stime));
+        spin_unlock(&sbi->ll_lock);
+
+        return len;
+}
+
+struct file_operations llite_wait_times_fops = {
+        .owner   = THIS_MODULE,
+        .open    = llite_wait_times_seq_open,
+        .read    = seq_read,
+        .write   = llite_wait_times_seq_write,
+        .llseek  = seq_lseek,
+        .release = seq_release,
 };
 
 #endif /* LPROCFS */