Skip to contentSkip to conversation

Resource Groups over generic containers

PATCH Balbir Singh 2 participants 4 messages Nov 5, 2006 – Nov 6, 2006 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

Hi, Paul,

I've just started playing with the new patchset and found a few issues.

Quoted 7 lines · [email protected] wrote:
(quoted diff) +7 -0
+ssize_t res_group_file_write(struct container *cont,
+				   struct cftype *cft,
+				   struct file *file,
+				   const char __user *userbuf,
+				   size_t nbytes, loff_t *ppos)
+{
+	struct res_group_cft *rgcft = container_of(cft, struct res_group_cft, cft);

Review

Quoted 10 lines
(quoted diff) +10 -0
+	struct res_controller *ctlr = rgcft->ctlr;
+
+	if (nbytes >= PAGE_SIZE)
+		return -E2BIG;
+
+	char *buf;
+	ssize_t retval;
+	int filetype = cft->private;
+
+	buf = kmalloc(nbytes + 1, GFP_USER);

This should be kmalloc(nbytes), an echo ".." has a "\n" associated with it.

Review

Quoted 7 lines
(quoted diff) +7 -0
+	if (!buf) return -ENOMEM;
+	if (copy_from_user(buf, userbuf, nbytes)) {
+		retval = -EFAULT;
+		goto out1;
+	}
+	buf[nbytes] = 0;	/* nul-terminate */
+

this should be buf[nbytes - 1]

Signature · 3 lines
	Balbir Singh,
	Linux Technology Center,
	IBM Software Labs
#3 lore raw
Quoted 2 lines · Balbir

This should be kmalloc(nbytes), an echo ".." has a "\n" associated with it.

But a:
write(1, "..", 2);
does not have a trialing newline.

If some consumer of this kernel buffer copy of what the user wrote cannot handle the possible trailing whitespace, they will have to chomp (Perl phrase) it off. You can't just whack one byte blindly.

At least for the kernel/cpuset.c code, from whence this came, the consumers of this kernel buffer copy are such routines as simple_strtoul() and cpulist_parse(), both of which cope with trailing newlines.

Signature · 3 lines
                  I won't rest till it's the best ...
                  Programmer, Linux Scalability
                  Paul Jackson <[email protected]> 1.925.600.0401
#4 lore raw
Quoted 7 lines · Paul Jackson
Quoted 2 lines · Balbir

This should be kmalloc(nbytes), an echo ".." has a "\n" associated with it.

But a:
write(1, "..", 2);
does not have a trialing newline.

Yes, true.

Quoted 6 lines

If some consumer of this kernel buffer copy of what the user wrote cannot handle the possible trailing whitespace, they will have to chomp (Perl phrase) it off. You can't just whack one byte blindly.

Yes, agreed.

Quoted 5 lines

At least for the kernel/cpuset.c code, from whence this came, the consumers of this kernel buffer copy are such routines as simple_strtoul() and cpulist_parse(), both of which cope with trailing newlines.

The problem I have is that match_token() that's used by the resource group's infrastructure cannot deal with "\n". I think the code needs in res_groups needs to get smarter like the code in simple_strtoul()

Signature · 4 lines
	Thanks for the feedback,
	Balbir Singh,
	Linux Technology Center,
	IBM Software Labs
#5 lore raw
In reply to Paul Jackson
Quoted 7 lines · Paul Jackson
Quoted 2 lines · Balbir

This should be kmalloc(nbytes), an echo ".." has a "\n" associated with it.

But a:
write(1, "..", 2);
does not have a trialing newline.

Yes, true.

Quoted 6 lines

If some consumer of this kernel buffer copy of what the user wrote cannot handle the possible trailing whitespace, they will have to chomp (Perl phrase) it off. You can't just whack one byte blindly.

Yes, agreed.

Quoted 5 lines

At least for the kernel/cpuset.c code, from whence this came, the consumers of this kernel buffer copy are such routines as simple_strtoul() and cpulist_parse(), both of which cope with trailing newlines.

The problem I have is that match_token() that's used by the resource group's infrastructure cannot deal with "\n". I think the code needs in res_groups needs to get smarter like the code in simple_strtoul()

Signature · 4 lines
	Thanks for the feedback,
	Balbir Singh,
	Linux Technology Center,
	IBM Software Labs