Re: [Patch 2/3] sysctl: add proc_do_large_bitmap

Previous thread: Re: [PATCH 3/4] KVM MMU: allow shadow page become unsync at creating time by Avi Kivity on Friday, April 30, 2010 - 2:54 am. (1 message)

Next thread: [Patch 1/3] sysctl: refactor integer handling proc code by Amerigo Wang on Friday, April 30, 2010 - 1:25 am. (3 messages)
From: Amerigo Wang
Date: Friday, April 30, 2010 - 1:25 am

From: Octavian Purdila <opurdila@ixiacom.com>

The new function can be used to read/write large bitmaps via /proc. A
comma separated range format is used for compact output and input
(e.g. 1,3-4,10-10).

Writing into the file will first reset the bitmap then update it
based on the given input.

Signed-off-by: Octavian Purdila <opurdila@ixiacom.com>
Signed-off-by: WANG Cong <amwang@redhat.com>
Cc: Eric W. Biederman <ebiederm@xmission.com>
---

Index: linux-2.6/include/linux/sysctl.h
===================================================================
--- linux-2.6.orig/include/linux/sysctl.h
+++ linux-2.6/include/linux/sysctl.h
@@ -980,6 +980,8 @@ extern int proc_doulongvec_minmax(struct
 				  void __user *, size_t *, loff_t *);
 extern int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int,
 				      void __user *, size_t *, loff_t *);
+extern int proc_do_large_bitmap(struct ctl_table *, int,
+				void __user *, size_t *, loff_t *);
 
 /*
  * Register a set of sysctl names by calling register_sysctl_table
Index: linux-2.6/kernel/sysctl.c
===================================================================
--- linux-2.6.orig/kernel/sysctl.c
+++ linux-2.6/kernel/sysctl.c
@@ -2049,6 +2049,16 @@ static size_t proc_skip_spaces(char **bu
 	return ret;
 }
 
+static void proc_skip_char(char **buf, size_t *size, const char v)
+{
+	while (*size) {
+		if (**buf != v)
+			break;
+		(*size)--;
+		(*buf)++;
+	}
+}
+
 #define TMPBUFLEN 22
 /**
  * proc_get_long - reads an ASCII formated integer from a user buffer
@@ -2675,6 +2685,153 @@ static int proc_do_cad_pid(struct ctl_ta
 	return 0;
 }
 
+/**
+ * proc_do_large_bitmap - read/write from/to a large bitmap
+ * @table: the sysctl table
+ * @write: %TRUE if this is a write to the sysctl file
+ * @buffer: the user buffer
+ * @lenp: the size of the user buffer
+ * @ppos: file position
+ *
+ * The bitmap is stored at table->data and the bitmap length (in bits)
+ * in table->maxlen.
+ *
+ * We use a ...
From: Changli Gao
Date: Friday, April 30, 2010 - 3:41 pm

add the following lines to let "echo 1-10 >>
/proc/..." work as normal.
                     if (write && *ppos)
                           bimap_or(bitmap, bitmap, tmp_bitmap,....)





-- 
Regards,
Changli Gao(xiaosuo@gmail.com)
From: Cong Wang
Date: Tuesday, May 4, 2010 - 8:14 pm

Hmm, I haven't tested this, what did you see if we append
lines into it?

Also, do we need appending lines to this /proc file when design it?
Octavian? Eric?

Thanks.
--

From: Cong Wang
Date: Wednesday, May 5, 2010 - 2:20 am

Hmm, currently this behaves like other /proc files, IOW,
echo 'foo' >> /proc/XXX is the same with echo 'foo' > /proc/XXX.

I think it is reasonable for bitmap /proc files to have
echo 'foo' >> /proc/XXX behaves like non-proc files, that is
appending numbers into that file, like what Changli mentioned.

Any objections?

Thanks.
--

Previous thread: Re: [PATCH 3/4] KVM MMU: allow shadow page become unsync at creating time by Avi Kivity on Friday, April 30, 2010 - 2:54 am. (1 message)

Next thread: [Patch 1/3] sysctl: refactor integer handling proc code by Amerigo Wang on Friday, April 30, 2010 - 1:25 am. (3 messages)