fs: dlm: add lkb debugfs functionality
[linux-2.6-microblaze.git] / fs / dlm / debug_fs.c
index 555904e..2ead475 100644 (file)
@@ -635,6 +635,35 @@ static int table_open2(struct inode *inode, struct file *file)
        return 0;
 }
 
+static ssize_t table_write2(struct file *file, const char __user *user_buf,
+                           size_t count, loff_t *ppos)
+{
+       struct seq_file *seq = file->private_data;
+       int n, len, lkb_nodeid, lkb_status, error;
+       char name[DLM_RESNAME_MAXLEN] = {};
+       struct dlm_ls *ls = seq->private;
+       unsigned int lkb_flags;
+       char buf[256] = {};
+       uint32_t lkb_id;
+
+       if (copy_from_user(buf, user_buf,
+                          min_t(size_t, sizeof(buf) - 1, count)))
+               return -EFAULT;
+
+       n = sscanf(buf, "%x %" __stringify(DLM_RESNAME_MAXLEN) "s %x %d %d",
+                  &lkb_id, name, &lkb_flags, &lkb_nodeid, &lkb_status);
+       if (n != 5)
+               return -EINVAL;
+
+       len = strnlen(name, DLM_RESNAME_MAXLEN);
+       error = dlm_debug_add_lkb(ls, lkb_id, name, len, lkb_flags,
+                                 lkb_nodeid, lkb_status);
+       if (error)
+               return error;
+
+       return count;
+}
+
 static int table_open3(struct inode *inode, struct file *file)
 {
        struct seq_file *seq;
@@ -675,6 +704,7 @@ static const struct file_operations format2_fops = {
        .owner   = THIS_MODULE,
        .open    = table_open2,
        .read    = seq_read,
+       .write   = table_write2,
        .llseek  = seq_lseek,
        .release = seq_release
 };
@@ -846,7 +876,7 @@ void dlm_create_debug_file(struct dlm_ls *ls)
        snprintf(name, DLM_LOCKSPACE_LEN + 8, "%s_locks", ls->ls_name);
 
        ls->ls_debug_locks_dentry = debugfs_create_file(name,
-                                                       S_IFREG | S_IRUGO,
+                                                       0644,
                                                        dlm_root,
                                                        ls,
                                                        &format2_fops);