mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 18:21:39 +01:00
Remove iflag argument to xs_write
xs_write with O_CREAT|O_EXCL causes problems over daemon restarts, since it's not idempotent. It turns out noone really needs the flags word at all, so get rid of it. It's now as if everyone specified "O_CREAT". Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
This commit is contained in:
1 parent
265d719ce5
commit
7fd9bccce2
29 files changed
+137
-293
No files matched your search
@@ -116,8 +116,6 @@ static PyObject *xspy_read(PyObject *self, PyObject *args, PyObject *kwds)
|
||||
"Write data to a path.\n" \
|
||||
" path [string] : xenstore path to write to\n." \
|
||||
" data [string] : data to write.\n" \
|
||||
" create [int] : create flag, default 0.\n" \
|
||||
" excl [int] : exclusive flag, default 0.\n" \
|
||||
"\n" \
|
||||
"Returns None on success.\n" \
|
||||
"Raises RuntimeError on error.\n" \
|
||||
@@ -125,30 +123,23 @@ static PyObject *xspy_read(PyObject *self, PyObject *args, PyObject *kwds)
|
||||
|
||||
static PyObject *xspy_write(PyObject *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
static char *kwd_spec[] = { "path", "data", "create", "excl", NULL };
|
||||
static char *arg_spec = "ss#|ii";
|
||||
static char *kwd_spec[] = { "path", "data", NULL };
|
||||
static char *arg_spec = "ss#";
|
||||
char *path = NULL;
|
||||
char *data = NULL;
|
||||
int data_n = 0;
|
||||
int create = 0;
|
||||
int excl = 0;
|
||||
|
||||
struct xs_handle *xh = xshandle(self);
|
||||
PyObject *val = NULL;
|
||||
int flags = 0;
|
||||
int xsval = 0;
|
||||
|
||||
if (!xh)
|
||||
goto exit;
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
|
||||
&path, &data, &data_n, &create, &excl))
|
||||
&path, &data, &data_n))
|
||||
goto exit;
|
||||
if (create)
|
||||
flags |= O_CREAT;
|
||||
if (excl)
|
||||
flags |= O_EXCL;
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
xsval = xs_write(xh, path, data, data_n, flags);
|
||||
xsval = xs_write(xh, path, data, data_n);
|
||||
Py_END_ALLOW_THREADS
|
||||
if (!xsval) {
|
||||
PyErr_SetFromErrno(PyExc_RuntimeError);
|
||||
|
||||
@@ -255,7 +255,7 @@ class XenStore:
|
||||
if x == "": continue
|
||||
p = os.path.join(p, x)
|
||||
if not self.exists(p):
|
||||
self.getxs().write(p, "", create=True)
|
||||
self.getxs().write(p, "")
|
||||
|
||||
def read(self, path):
|
||||
try:
|
||||
@@ -266,13 +266,12 @@ class XenStore:
|
||||
else:
|
||||
raise
|
||||
|
||||
def create(self, path, excl=False):
|
||||
self.write(path, "", create=True, excl=excl)
|
||||
def create(self, path):
|
||||
self.write(path, "")
|
||||
|
||||
def write(self, path, data, create=True, excl=False):
|
||||
self.mkdirs(path)
|
||||
def write(self, path, data):
|
||||
try:
|
||||
self.getxs().write(path, data, create=create, excl=excl)
|
||||
self.getxs().write(path, data)
|
||||
except Exception, ex:
|
||||
raise
|
||||
|
||||
|
||||
@@ -53,13 +53,11 @@ class xstransact:
|
||||
ret.append(self._read(key))
|
||||
return ret
|
||||
|
||||
def _write(self, key, data, create=True, excl=False):
|
||||
def _write(self, key, data):
|
||||
path = "%s/%s" % (self.path, key)
|
||||
xshandle().write(path, data, create=create, excl=excl)
|
||||
xshandle().write(path, data)
|
||||
|
||||
def write(self, *args, **opts):
|
||||
create = opts.get('create') or True
|
||||
excl = opts.get('excl') or False
|
||||
if len(args) == 0:
|
||||
raise TypeError
|
||||
if isinstance(args[0], dict):
|
||||
@@ -68,19 +66,18 @@ class xstransact:
|
||||
raise TypeError
|
||||
for key in d.keys():
|
||||
try:
|
||||
self._write(key, d[key], create, excl)
|
||||
self._write(key, d[key])
|
||||
except TypeError, msg:
|
||||
raise TypeError('Writing %s: %s: %s' %
|
||||
(key, str(d[key]), msg))
|
||||
|
||||
elif isinstance(args[0], list):
|
||||
for l in args:
|
||||
if not len(l) == 2:
|
||||
raise TypeError
|
||||
self._write(l[0], l[1], create, excl)
|
||||
self._write(l[0], l[1])
|
||||
elif len(args) % 2 == 0:
|
||||
for i in range(len(args) / 2):
|
||||
self._write(args[i * 2], args[i * 2 + 1], create, excl)
|
||||
self._write(args[i * 2], args[i * 2 + 1])
|
||||
else:
|
||||
raise TypeError
|
||||
|
||||
|
||||