Whamcloud - gitweb
- added comment in mds_open() and GNS mount points.
[fs/lustre-release.git] / lustre / llite / lproc_llite.c
index 1b05eb9..2871ab7 100644 (file)
 #include <linux/lprocfs_status.h>
 #include <linux/seq_file.h>
 #include <linux/obd_support.h>
+#ifdef HAVE_MM_INLINE
+#include <linux/mm_inline.h>
+#endif
 
 #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,
@@ -202,8 +207,8 @@ 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))
+        
+        if (sscanf(buffer, "%d", &readahead) != 1)
                 RETURN(-EINVAL);
 
         if (readahead)
@@ -233,7 +238,7 @@ static int ll_rd_max_read_ahead_mb(char *page, char **start, off_t off,
         unsigned val;
 
         spin_lock(&sbi->ll_lock);
-        val = (sbi->ll_max_read_ahead_pages << PAGE_CACHE_SHIFT) >> 20;
+        val = (sbi->ll_ra_info.ra_max_pages << PAGE_CACHE_SHIFT) >> 20;
         spin_unlock(&sbi->ll_lock);
 
         return snprintf(page, count, "%u\n", val);
@@ -254,12 +259,143 @@ static int ll_wr_max_read_ahead_mb(struct file *file, const char *buffer,
                 return -ERANGE;
 
         spin_lock(&sbi->ll_lock);
-        sbi->ll_max_read_ahead_pages = (val << 20) >> PAGE_CACHE_SHIFT;
+        sbi->ll_ra_info.ra_max_pages = (val << 20) >> PAGE_CACHE_SHIFT;
         spin_unlock(&sbi->ll_lock);
 
         return count;
 }
 
+static int ll_rd_gns_upcall(char *page, char **start, off_t off,
+                            int count, int *eof, void *data)
+{
+        struct super_block *sb = (struct super_block *)data;
+        struct ll_sb_info *sbi = ll_s2sbi(sb);
+        int len;
+
+        down(&sbi->ll_gns_sem);
+        len = snprintf(page, count, "%s\n", sbi->ll_gns_upcall);
+        up(&sbi->ll_gns_sem);
+
+        return len;
+}
+
+static int ll_wr_gns_upcall(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);
+
+        down(&sbi->ll_gns_sem);
+        snprintf(sbi->ll_gns_upcall, count, "%s", buffer);
+        up(&sbi->ll_gns_sem);
+
+        return count;
+}
+
+static int ll_rd_gns_object_name(char *page, char **start, off_t off,
+                                 int count, int *eof, void *data)
+{
+        struct super_block *sb = (struct super_block *)data;
+        struct ll_sb_info *sbi = ll_s2sbi(sb);
+        int len;
+
+        down(&sbi->ll_gns_sem);
+        len = snprintf(page, count, "%s\n", sbi->ll_gns_oname);
+        up(&sbi->ll_gns_sem);
+
+        return len;
+}
+
+static int ll_wr_gns_object_name(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);
+
+        /* checking for setting "." and ".." as object name */
+        if (buffer[0] == '.') switch (count) {
+                case 2:
+                        /* this is "." case with terminating zero */
+                        return -EINVAL;
+                case 3:
+                        /* this is ".." case with terminating zero */
+                        if (buffer[1] == '.')
+                                return -EINVAL;
+        }
+        
+        down(&sbi->ll_gns_sem);
+        snprintf(sbi->ll_gns_oname, count, "%s", buffer);
+        up(&sbi->ll_gns_sem);
+
+        return count;
+}
+
+static int ll_rd_gns_timeout(char *page, char **start, off_t off,
+                             int count, int *eof, void *data)
+{
+        struct super_block *sb = (struct super_block *)data;
+        struct ll_sb_info *sbi = ll_s2sbi(sb);
+        int len;
+
+        down(&sbi->ll_gns_sem);
+        len = snprintf(page, count, "%lu\n",
+                       (unsigned long)sbi->ll_gns_timeout);
+        up(&sbi->ll_gns_sem);
+
+        return len;
+}
+
+static int ll_wr_gns_timeout(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);
+        int val, rc;
+
+        rc = lprocfs_write_helper(buffer, count, &val);
+        if (rc)
+                return rc;
+
+        down(&sbi->ll_gns_sem);
+        sbi->ll_gns_timeout = val;
+        up(&sbi->ll_gns_sem);
+
+        return count;
+}
+
+static int ll_rd_gns_tick(char *page, char **start, off_t off,
+                          int count, int *eof, void *data)
+{
+        struct super_block *sb = (struct super_block *)data;
+        struct ll_sb_info *sbi = ll_s2sbi(sb);
+        int len;
+
+        down(&sbi->ll_gns_sem);
+        len = snprintf(page, count, "%lu\n",
+                       (unsigned long)sbi->ll_gns_tick);
+        up(&sbi->ll_gns_sem);
+
+        return len;
+}
+
+static int ll_wr_gns_tick(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);
+        int val, rc;
+
+        rc = lprocfs_write_helper(buffer, count, &val);
+        if (rc)
+                return rc;
+
+        down(&sbi->ll_gns_sem);
+        if (sbi->ll_gns_tick < sbi->ll_gns_timeout)
+                sbi->ll_gns_tick = val;
+        up(&sbi->ll_gns_sem);
+
+        return count;
+}
 static struct lprocfs_vars lprocfs_obd_vars[] = {
         { "uuid",         ll_rd_sb_uuid,          0, 0 },
         //{ "mntpt_path",   ll_rd_path,             0, 0 },
@@ -275,6 +411,19 @@ static struct lprocfs_vars lprocfs_obd_vars[] = {
         { "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 },
+
+        { "gns_upcall", ll_rd_gns_upcall,
+          ll_wr_gns_upcall, 0 },
+        
+        { "gns_timeout", ll_rd_gns_timeout,
+          ll_wr_gns_timeout, 0 },
+        
+        { "gns_tick", ll_rd_gns_tick,
+          ll_wr_gns_tick, 0 },
+        
+        { "gns_object_name", ll_rd_gns_object_name,
+          ll_wr_gns_object_name, 0 },
+        
         { 0 }
 };
 
@@ -326,7 +475,8 @@ struct llite_file_opcode {
                                    "direct_read" },
         { LPROC_LL_DIRECT_WRITE,   LPROCFS_CNTR_AVGMINMAX|LPROCFS_TYPE_PAGES,
                                    "direct_write" },
-
+        { LPROC_LL_SETXATTR,       LPROCFS_TYPE_REGS, "setxattr" },
+        { LPROC_LL_GETXATTR,       LPROCFS_TYPE_REGS, "getxattr" },
 };
 
 int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
@@ -368,6 +518,18 @@ int lprocfs_register_mountpoint(struct proc_dir_entry *parent,
         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;
@@ -494,8 +656,8 @@ static int llite_dump_pgcache_seq_show(struct seq_file *seq, void *v)
         /* 2.4 doesn't seem to have SEQ_START_TOKEN, so we implement
          * it in our own state */
         if (dummy_llap->llap_magic == 0) {
-                seq_printf(seq, "generation | llap .cookie | page ");
-                seq_printf(seq, "inode .index [ page flags ]\n");
+                seq_printf(seq, "generation | llap cookie origin | page ");
+                seq_printf(seq, "inode index count [ page flags ]\n");
                 return 0;
         }
 
@@ -505,11 +667,23 @@ static int llite_dump_pgcache_seq_show(struct seq_file *seq, void *v)
         if (llap != NULL)  {
                 int has_flags = 0;
                 struct page *page = llap->llap_page;
-
-                seq_printf(seq, "%lu | %p %p | %p %p %lu [",
+                static char *origins[] = {
+                        [LLAP_ORIGIN_UNKNOWN] = "--",
+                        [LLAP_ORIGIN_READPAGE] = "rp",
+                        [LLAP_ORIGIN_READAHEAD] = "ra",
+                        [LLAP_ORIGIN_COMMIT_WRITE] = "cw",
+                        [LLAP_ORIGIN_WRITEPAGE] = "wp",
+                };
+
+                LASSERTF(llap->llap_origin < LLAP__ORIGIN_MAX, "%u\n",
+                         llap->llap_origin);
+
+                seq_printf(seq, "%lu | %p %p %s | %p %p %lu %u [",
                                 sbi->ll_pglist_gen,
                                 llap, llap->llap_cookie,
-                                page, page->mapping->host, page->index);
+                                origins[llap->llap_origin],
+                                page, page->mapping->host, page->index,
+                                page_count(page));
                 seq_page_flag(seq, page, locked, has_flags);
                 seq_page_flag(seq, page, error, has_flags);
                 seq_page_flag(seq, page, referenced, has_flags);
@@ -643,5 +817,203 @@ struct file_operations llite_dump_pgcache_fops = {
         .read    = seq_read,
         .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 */