direct-io.hg

changeset 7304:e43ffb31de48

Fix xenbus internal join() function to be concurrency safe
(no static string buffer).

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Tue Oct 11 11:59:15 2005 +0100 (2005-10-11)
parents 90f4f4dc3f62
children 5cca372aec05
files linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c
line diff
     1.1 --- a/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Tue Oct 11 10:33:31 2005 +0100
     1.2 +++ b/linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c	Tue Oct 11 11:59:15 2005 +0100
     1.3 @@ -269,18 +269,22 @@ static unsigned int count_strings(const 
     1.4  	return num;
     1.5  }
     1.6  
     1.7 -/* Return the path to dir with /name appended. */ 
     1.8 +/* Return the path to dir with /name appended. Buffer must be kfree()'ed. */ 
     1.9  static char *join(const char *dir, const char *name)
    1.10  {
    1.11 -	static char buffer[4096];
    1.12 +	char *buffer;
    1.13  
    1.14 -	BUG_ON(strlen(dir) + strlen("/") + strlen(name) + 1 > sizeof(buffer));
    1.15 +	buffer = kmalloc(strlen(dir) + strlen("/") + strlen(name) + 1,
    1.16 +			 GFP_KERNEL);
    1.17 +	if (buffer == NULL)
    1.18 +		return ERR_PTR(-ENOMEM);
    1.19  
    1.20  	strcpy(buffer, dir);
    1.21  	if (!streq(name, "")) {
    1.22  		strcat(buffer, "/");
    1.23  		strcat(buffer, name);
    1.24  	}
    1.25 +
    1.26  	return buffer;
    1.27  }
    1.28  
    1.29 @@ -310,10 +314,15 @@ static char **split(char *strings, unsig
    1.30  char **xenbus_directory(struct xenbus_transaction *t,
    1.31  			const char *dir, const char *node, unsigned int *num)
    1.32  {
    1.33 -	char *strings;
    1.34 +	char *strings, *path;
    1.35  	unsigned int len;
    1.36  
    1.37 -	strings = xs_single(t, XS_DIRECTORY, join(dir, node), &len);
    1.38 +	path = join(dir, node);
    1.39 +	if (IS_ERR(path))
    1.40 +		return (char **)path;
    1.41 +
    1.42 +	strings = xs_single(t, XS_DIRECTORY, path, &len);
    1.43 +	kfree(path);
    1.44  	if (IS_ERR(strings))
    1.45  		return (char **)strings;
    1.46  
    1.47 @@ -343,7 +352,16 @@ EXPORT_SYMBOL(xenbus_exists);
    1.48  void *xenbus_read(struct xenbus_transaction *t,
    1.49  		  const char *dir, const char *node, unsigned int *len)
    1.50  {
    1.51 -	return xs_single(t, XS_READ, join(dir, node), len);
    1.52 +	char *path;
    1.53 +	void *ret;
    1.54 +
    1.55 +	path = join(dir, node);
    1.56 +	if (IS_ERR(path))
    1.57 +		return (void *)path;
    1.58 +
    1.59 +	ret = xs_single(t, XS_READ, path, len);
    1.60 +	kfree(path);
    1.61 +	return ret;
    1.62  }
    1.63  EXPORT_SYMBOL(xenbus_read);
    1.64  
    1.65 @@ -355,15 +373,20 @@ int xenbus_write(struct xenbus_transacti
    1.66  {
    1.67  	const char *path;
    1.68  	struct kvec iovec[2];
    1.69 +	int ret;
    1.70  
    1.71  	path = join(dir, node);
    1.72 +	if (IS_ERR(path))
    1.73 +		return PTR_ERR(path);
    1.74  
    1.75  	iovec[0].iov_base = (void *)path;
    1.76  	iovec[0].iov_len = strlen(path) + 1;
    1.77  	iovec[1].iov_base = (void *)string;
    1.78  	iovec[1].iov_len = strlen(string);
    1.79  
    1.80 -	return xs_error(xs_talkv(t, XS_WRITE, iovec, ARRAY_SIZE(iovec), NULL));
    1.81 +	ret = xs_error(xs_talkv(t, XS_WRITE, iovec, ARRAY_SIZE(iovec), NULL));
    1.82 +	kfree(path);
    1.83 +	return ret;
    1.84  }
    1.85  EXPORT_SYMBOL(xenbus_write);
    1.86  
    1.87 @@ -371,14 +394,32 @@ EXPORT_SYMBOL(xenbus_write);
    1.88  int xenbus_mkdir(struct xenbus_transaction *t,
    1.89  		 const char *dir, const char *node)
    1.90  {
    1.91 -	return xs_error(xs_single(t, XS_MKDIR, join(dir, node), NULL));
    1.92 +	char *path;
    1.93 +	int ret;
    1.94 +
    1.95 +	path = join(dir, node);
    1.96 +	if (IS_ERR(path))
    1.97 +		return PTR_ERR(path);
    1.98 +
    1.99 +	ret = xs_error(xs_single(t, XS_MKDIR, path, NULL));
   1.100 +	kfree(path);
   1.101 +	return ret;
   1.102  }
   1.103  EXPORT_SYMBOL(xenbus_mkdir);
   1.104  
   1.105  /* Destroy a file or directory (directories must be empty). */
   1.106  int xenbus_rm(struct xenbus_transaction *t, const char *dir, const char *node)
   1.107  {
   1.108 -	return xs_error(xs_single(t, XS_RM, join(dir, node), NULL));
   1.109 +	char *path;
   1.110 +	int ret;
   1.111 +
   1.112 +	path = join(dir, node);
   1.113 +	if (IS_ERR(path))
   1.114 +		return PTR_ERR(path);
   1.115 +
   1.116 +	ret = xs_error(xs_single(t, XS_RM, path, NULL));
   1.117 +	kfree(path);
   1.118 +	return ret;
   1.119  }
   1.120  EXPORT_SYMBOL(xenbus_rm);
   1.121