[sanlock] branch master updated: sanlock: Report actual
max_worker_threads
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
The following commit(s) were added to refs/heads/master by this push:
new 32a73a5 sanlock: Report actual max_worker_threads
32a73a5 is described below
commit 32a73a539432dbbca7187ddafd4a2b2ae91ea1f8
Author: Nir Soffer <nsoffer(a)redhat.com>
AuthorDate: Sun Dec 6 20:14:11 2020 +0200
sanlock: Report actual max_worker_threads
Report actual max_worker_threads in "sanlock client status -D". This
allows detecting the issue when sanlock configuration was updated, but
sanlock daemon needs a restart to pick up the new configuration.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
src/cmd.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/cmd.c b/src/cmd.c
index a5fa30f..3137df0 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -2265,6 +2265,7 @@ static int print_state_daemon(char *str)
"max_sectors_kb_ignore=%d "
"max_sectors_kb_align=%d "
"max_sectors_kb_num=%d "
+ "max_worker_threads=%d "
"write_init_io_timeout=%u "
"use_aio=%d "
"kill_grace_seconds=%d "
@@ -2292,6 +2293,7 @@ static int print_state_daemon(char *str)
com.max_sectors_kb_ignore,
com.max_sectors_kb_align,
com.max_sectors_kb_num,
+ com.max_worker_threads,
com.write_init_io_timeout,
main_task.use_aio,
kill_grace_seconds,
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
3 years, 4 months
[PATCH] sanlock: Report actual max_worker_threads
by Nir Soffer
Report actual max_worker_threads in "sanlock client status -D". This
allows detecting the issue when sanlock configuration was updated, but
sanlock daemon needs a restart to pick up the new configuration.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
src/cmd.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/cmd.c b/src/cmd.c
index a5fa30f..3137df0 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -2265,6 +2265,7 @@ static int print_state_daemon(char *str)
"max_sectors_kb_ignore=%d "
"max_sectors_kb_align=%d "
"max_sectors_kb_num=%d "
+ "max_worker_threads=%d "
"write_init_io_timeout=%u "
"use_aio=%d "
"kill_grace_seconds=%d "
@@ -2292,6 +2293,7 @@ static int print_state_daemon(char *str)
com.max_sectors_kb_ignore,
com.max_sectors_kb_align,
com.max_sectors_kb_num,
+ com.max_worker_threads,
com.write_init_io_timeout,
main_task.use_aio,
kill_grace_seconds,
--
2.26.2
3 years, 4 months
[sanlock] 04/04: tests: add a test for LVB operation
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
teigland pushed a commit to branch master
in repository sanlock.
commit 74a403464b0bb4c2a64ed3dc4f11127e3870fa05
Author: Benny Zlotnik <bzlotnik(a)redhat.com>
AuthorDate: Mon Oct 5 13:20:27 2020 +0300
tests: add a test for LVB operation
This patch tests writing and reading to LVB via python bindings.
Signed-off-by: Benny Zlotnik <bzlotnik(a)redhat.com>
---
tests/python_test.py | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 72 insertions(+)
diff --git a/tests/python_test.py b/tests/python_test.py
index abd459e..28fd27f 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -764,3 +764,75 @@ def test_acquire_path_length(no_sanlock_daemon):
path = "x" * (constants.SANLK_PATH_LEN - 1)
with raises_sanlock_errno():
sanlock.acquire(b"ls_name", b"res_name", [(path, 0)], pid=os.getpid())
+
+
+def test_lvb(tmpdir, sanlock_daemon):
+ ls_path = str(tmpdir.join("ls_name"))
+ util.create_file(ls_path, MiB)
+
+ res_path = str(tmpdir.join("res_name"))
+ util.create_file(res_path, MiB)
+
+ sanlock.write_lockspace(b"ls_name", ls_path, offset=0, iotimeout=1)
+ sanlock.add_lockspace(b"ls_name", 1, ls_path, offset=0, iotimeout=1)
+
+ disks = [(res_path, 0)]
+ sanlock.write_resource(b"ls_name", b"res_name", disks)
+
+ fd = sanlock.register()
+
+ sanlock.acquire(b"ls_name", b"res_name", disks, slkfd=fd, lvb=True)
+ sanlock.set_lvb(b"ls_name", b"res_name", disks, b"{gen:0}")
+
+ result = sanlock.get_lvb(b"ls_name", b"res_name", disks)
+ sanlock.release(b"ls_name", b"res_name", disks, slkfd=fd)
+
+ assert result == b"{gen:0}"
+
+
+def test_lvb_value_too_long(tmpdir, sanlock_daemon):
+ ls_path = str(tmpdir.join("ls_name"))
+ util.create_file(ls_path, MiB)
+
+ res_path = str(tmpdir.join("res_name"))
+ util.create_file(res_path, MiB)
+
+ sanlock.write_lockspace(b"ls_name", ls_path, offset=0, iotimeout=1)
+ sanlock.add_lockspace(b"ls_name", 1, ls_path, offset=0, iotimeout=1)
+
+ disks = [(res_path, 0)]
+ sanlock.write_resource(b"ls_name", b"res_name", disks)
+
+ fd = sanlock.register()
+
+ long_val = b"a" * 513
+ sanlock.acquire(b"ls_name", b"res_name", disks, slkfd=fd, lvb=True)
+ with raises_sanlock_errno(errno.E2BIG):
+ sanlock.set_lvb(b"ls_name", b"res_name", disks, long_val)
+
+ sanlock.release(b"ls_name", b"res_name", disks, slkfd=fd)
+
+
+def test_lvb_null_bytes(tmpdir, sanlock_daemon):
+ ls_path = str(tmpdir.join("ls_name"))
+ util.create_file(ls_path, MiB)
+
+ res_path = str(tmpdir.join("res_name"))
+ util.create_file(res_path, MiB)
+
+ sanlock.write_lockspace(b"ls_name", ls_path, offset=0, iotimeout=1)
+ sanlock.add_lockspace(b"ls_name", 1, ls_path, offset=0, iotimeout=1)
+
+ disks = [(res_path, 0)]
+ sanlock.write_resource(b"ls_name", b"res_name", disks)
+
+ fd = sanlock.register()
+
+ sanlock.acquire(b"ls_name", b"res_name", disks, slkfd=fd, lvb=True)
+ sanlock.set_lvb(b"ls_name", b"res_name", disks, b"{ge\x00:0}")
+
+ result = sanlock.get_lvb(b"ls_name", b"res_name", disks)
+ sanlock.release(b"ls_name", b"res_name", disks, slkfd=fd)
+
+ # Check that the string we passed is terminated by the null-byte
+ assert result == b"{ge"
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
3 years, 4 months
[sanlock] 03/04: python: expose get_lvb
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
teigland pushed a commit to branch master
in repository sanlock.
commit 9034b7b9c7bae930c57de9d96dd8280343baf5f1
Author: Benny Zlotnik <bzlotnik(a)redhat.com>
AuthorDate: Mon Oct 5 13:18:05 2020 +0300
python: expose get_lvb
Add a binding to the get_lvb function to allow reading data from LVB.
Signed-off-by: Benny Zlotnik <bzlotnik(a)redhat.com>
---
python/sanlock.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)
diff --git a/python/sanlock.c b/python/sanlock.c
index 9647c03..fbcabb1 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -1649,6 +1649,63 @@ finally:
Py_RETURN_NONE;
}
+PyDoc_STRVAR(pydoc_get_lvb, "\
+get_lvb(lockspace, resource, disks) -> bytes\n\
+Read Lock Value Block for a given resource\n\
+\n\
+Arguments\n\
+ lockspace lockspace name (str)\n\
+ resource resource name (int)\n\
+ disks path and offset (tuple)\n\
+\n\
+Returns\n\
+ data data written with set_lvb\n\
+Notes\n\
+\n\
+The resource must be acquired with the SANLK_ACQUIRE_LVB flag\n");
+static PyObject *
+py_get_lvb(PyObject *self __unused, PyObject *args, PyObject *keywds)
+{
+ uint32_t flags = 0;
+ int rv = -1;
+ struct sanlk_resource *res = NULL;
+ PyObject *lockspace = NULL, *resource = NULL;
+ PyObject *disks;
+ char data[512];
+
+ static char *kwlist[] = {"lockspace", "resource", "disks", NULL};
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&O&O!", kwlist,
+ convert_to_pybytes, &lockspace, convert_to_pybytes, &resource,
+ &PyList_Type, &disks)) {
+ goto finally;
+ }
+
+ if (parse_disks(disks, &res) < 0) {
+ goto finally;
+ }
+
+ strncpy(res->lockspace_name, PyBytes_AsString(lockspace), SANLK_NAME_LEN);
+ strncpy(res->name, PyBytes_AsString(resource), SANLK_NAME_LEN);
+
+ Py_BEGIN_ALLOW_THREADS
+ rv = sanlock_get_lvb(flags, res, data, sizeof(data));
+ Py_END_ALLOW_THREADS
+
+ if (rv < 0) {
+ set_sanlock_error(rv, "Unable to get lvb");
+ goto finally;
+ }
+
+finally:
+ Py_XDECREF(lockspace);
+ Py_XDECREF(resource);
+ free(res);
+ if (rv < 0)
+ return NULL;
+
+ return Py_BuildValue("y", data);
+}
+
static PyMethodDef
sanlock_methods[] = {
{"register", py_register, METH_NOARGS, pydoc_register},
@@ -1688,6 +1745,8 @@ sanlock_methods[] = {
METH_VARARGS|METH_KEYWORDS, pydoc_set_event},
{"set_lvb", (PyCFunction) py_set_lvb,
METH_VARARGS|METH_KEYWORDS, pydoc_set_lvb},
+ {"get_lvb", (PyCFunction) py_get_lvb,
+ METH_VARARGS|METH_KEYWORDS, pydoc_get_lvb},
{NULL, NULL, 0, NULL}
};
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
3 years, 4 months
[sanlock] 02/04: python: expose set_lvb
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
teigland pushed a commit to branch master
in repository sanlock.
commit 2ea4446a06079a71266fd9f5066dd2909c7546d6
Author: Benny Zlotnik <bzlotnik(a)redhat.com>
AuthorDate: Mon Oct 5 13:04:13 2020 +0300
python: expose set_lvb
Add a binding to the set_lvb function to allow writing data to LVB.
Signed-off-by: Benny Zlotnik <bzlotnik(a)redhat.com>
---
python/sanlock.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)
diff --git a/python/sanlock.c b/python/sanlock.c
index 4592f7e..9647c03 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -1594,6 +1594,61 @@ finally:
Py_RETURN_NONE;
}
+/* set_lvb */
+PyDoc_STRVAR(pydoc_set_lvb, "\
+set_lvb(lockspace, resource, disks, data)\n\
+Set Lock Value Block for a given resource\n\
+\n\
+Arguments\n\
+ lockspace lockspace name (str)\n\
+ resource resource name (int)\n\
+ disks path and offset (tuple)\n\
+ data data to write (bytes)\n\
+\n\
+Notes\n\
+\n\
+The resource must be acquired with the SANLK_ACQUIRE_LVB flag\n");
+static PyObject *
+py_set_lvb(PyObject *self __unused, PyObject *args, PyObject *keywds)
+{
+ uint32_t flags = 0;
+ int rv = -1;
+ struct sanlk_resource *res = NULL;
+ PyObject *lockspace = NULL, *resource = NULL, *data = NULL;
+ PyObject *disks;
+
+ static char *kwlist[] = {"lockspace", "resource", "disks", "data", NULL};
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&O&O!O&", kwlist,
+ convert_to_pybytes, &lockspace, convert_to_pybytes, &resource,
+ &PyList_Type, &disks, convert_to_pybytes, &data)) {
+ goto finally;
+ }
+
+ if (parse_disks(disks, &res) < 0) {
+ goto finally;
+ }
+
+ strncpy(res->lockspace_name, PyBytes_AsString(lockspace), SANLK_NAME_LEN);
+ strncpy(res->name, PyBytes_AsString(resource), SANLK_NAME_LEN);
+
+ Py_BEGIN_ALLOW_THREADS
+ rv = sanlock_set_lvb(flags, res, PyBytes_AS_STRING(data), PyBytes_GET_SIZE(data));
+ Py_END_ALLOW_THREADS
+
+ if (rv < 0) {
+ set_sanlock_error(rv, "Unable to set lvb");
+ goto finally;
+ }
+
+finally:
+ Py_XDECREF(lockspace);
+ Py_XDECREF(resource);
+ free(res);
+ if (rv < 0)
+ return NULL;
+ Py_RETURN_NONE;
+}
+
static PyMethodDef
sanlock_methods[] = {
{"register", py_register, METH_NOARGS, pydoc_register},
@@ -1631,6 +1686,9 @@ sanlock_methods[] = {
{"end_event", (PyCFunction) py_end_event, METH_VARARGS, pydoc_end_event},
{"set_event", (PyCFunction) py_set_event,
METH_VARARGS|METH_KEYWORDS, pydoc_set_event},
+ {"set_lvb", (PyCFunction) py_set_lvb,
+ METH_VARARGS|METH_KEYWORDS, pydoc_set_lvb},
+
{NULL, NULL, 0, NULL}
};
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
3 years, 4 months
[sanlock] 01/04: python: add lvb flag to sanlock.acquire
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
teigland pushed a commit to branch master
in repository sanlock.
commit 4e36aad261de84c44318f4e14549cacb2578d913
Author: Benny Zlotnik <bzlotnik(a)redhat.com>
AuthorDate: Mon Oct 5 12:49:31 2020 +0300
python: add lvb flag to sanlock.acquire
The flag will allow to acquire a resource with the SANLK_ACQUIRE_LVB
flag, allowing the user to write or read data from LVB space.
Signed-off-by: Benny Zlotnik <bzlotnik(a)redhat.com>
---
python/sanlock.c | 21 ++++++++++++++-------
1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 6cdbbc9..4592f7e 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -981,28 +981,31 @@ finally:
/* acquire */
PyDoc_STRVAR(pydoc_acquire, "\
acquire(lockspace, resource, disks \
-[, slkfd=fd, pid=owner, shared=False, version=None])\n\
+[, slkfd=fd, pid=owner, shared=False, version=None, lvb=False])\n\
Acquire a resource lease for the current process (using the slkfd argument\n\
to specify the sanlock file descriptor) or for another process (using the\n\
pid argument). If shared is True the resource will be acquired in the shared\n\
mode. The version is the version of the lease that must be acquired or fail.\n\
-The disks must be in the format: [(path, offset), ... ]\n");
+The disks must be in the format: [(path, offset), ... ]\n\
+If lvb is True the resource will be acquired with the LVB flag enabled\n\
+to allow access to LVB data.\n");
static PyObject *
py_acquire(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv = -1, sanlockfd = -1, pid = -1, shared = 0;
+ int rv = -1, sanlockfd = -1, pid = -1, shared = 0, lvb = 0;
+ uint32_t flags = 0;
PyObject *lockspace = NULL, *resource = NULL;
struct sanlk_resource *res = NULL;
PyObject *disks, *version = Py_None;
static char *kwlist[] = {"lockspace", "resource", "disks", "slkfd",
- "pid", "shared", "version", NULL};
+ "pid", "shared", "lvb", "version", NULL};
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&O&O!|iiiO", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&O&O!|iiiiO", kwlist,
convert_to_pybytes, &lockspace, convert_to_pybytes, &resource,
- &PyList_Type, &disks, &sanlockfd, &pid, &shared, &version)) {
+ &PyList_Type, &disks, &sanlockfd, &pid, &shared, &lvb, &version)) {
goto finally;
}
@@ -1026,6 +1029,10 @@ py_acquire(PyObject *self __unused, PyObject *args, PyObject *keywds)
res->flags |= SANLK_RES_SHARED;
}
+ if (lvb) {
+ flags |= SANLK_ACQUIRE_LVB;
+ }
+
/* prepare the resource version */
if (version != Py_None) {
res->flags |= SANLK_RES_LVER;
@@ -1038,7 +1045,7 @@ py_acquire(PyObject *self __unused, PyObject *args, PyObject *keywds)
/* acquire sanlock resource (gil disabled) */
Py_BEGIN_ALLOW_THREADS
- rv = sanlock_acquire(sanlockfd, pid, 0, 1, &res, 0);
+ rv = sanlock_acquire(sanlockfd, pid, flags, 1, &res, 0);
Py_END_ALLOW_THREADS
if (rv != 0) {
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
3 years, 4 months
[sanlock] branch master updated: sanlock: Shrink thread pool when
there is no work
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
teigland pushed a commit to branch master
in repository sanlock.
The following commit(s) were added to refs/heads/master by this push:
new 0ff9c1a sanlock: Shrink thread pool when there is no work
0ff9c1a is described below
commit 0ff9c1ab8852bec846822ee2af55ebcb7e5f5967
Author: Nir Soffer <nirsof(a)gmail.com>
AuthorDate: Tue Dec 1 15:45:03 2020 +0200
sanlock: Shrink thread pool when there is no work
When the thread pool has no work to do, and we have enough free workers,
other worker threads will terminate.
Without this change, when using large number of worker threads, the
thread pool grows to max_worker_threads workers, and never shrink down.
With this change, the pool quickly shrinks down, but we always have
enough free worker threads for serving new requests.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
src/main.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/main.c b/src/main.c
index 63d8cff..622dc8e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -932,6 +932,9 @@ static void *thread_pool_worker(void *data)
while (1) {
while (!pool.quit && list_empty(&pool.work_data)) {
+ if (pool.free_workers >= DEFAULT_MIN_WORKER_THREADS)
+ goto out;
+
pool.free_workers++;
pthread_cond_wait(&pool.cond, &pool.mutex);
pool.free_workers--;
@@ -952,6 +955,7 @@ static void *thread_pool_worker(void *data)
break;
}
+out:
pool.num_workers--;
if (!pool.num_workers)
pthread_cond_signal(&pool.quit_wait);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
3 years, 4 months
[PATCH] sanlock: Shrink thread pool when there is no work
by Nir Soffer
When the thread pool has no work to do, and we have enough free workers,
other worker threads will terminate.
Without this change, when using large number of worker threads, the
thread pool grows to max_worker_threads workers, and never shrink down.
With this change, the pool quickly shrinks down, but we always have
enough free worker threads for serving new requests.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
src/main.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/main.c b/src/main.c
index 63d8cff..622dc8e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -932,6 +932,9 @@ static void *thread_pool_worker(void *data)
while (1) {
while (!pool.quit && list_empty(&pool.work_data)) {
+ if (pool.free_workers >= DEFAULT_MIN_WORKER_THREADS)
+ goto out;
+
pool.free_workers++;
pthread_cond_wait(&pool.cond, &pool.mutex);
pool.free_workers--;
@@ -952,6 +955,7 @@ static void *thread_pool_worker(void *data)
break;
}
+out:
pool.num_workers--;
if (!pool.num_workers)
pthread_cond_signal(&pool.quit_wait);
--
2.26.2
3 years, 4 months