From f5e52561d66f3777e4ec75992e52200779d9add1 Mon Sep 17 00:00:00 2001 From: Anoop C S Date: Wed, 4 Feb 2015 10:34:33 +0530 Subject: features/locks: Implement mandatory locks Initial change to fix/enable the mandatory locking support in GlusterFS as per the following design: https://review.gluster.org/#/c/12014/ Accordingly 'locks.mandatory-locking' option is available as part of this change which will accept one among the following values: * off * file * forced * optimal See design doc for more details > Reviewed-on: http://review.gluster.org/9768 > Smoke: Gluster Build System > CentOS-regression: Gluster Build System > NetBSD-regression: NetBSD Build System > Reviewed-by: Poornima G > Reviewed-by: Raghavendra Talur > Reviewed-by: Rajesh Joseph > Reviewed-by: Pranith Kumar Karampuri (cherry picked from commit 4517bf8dd6de310950cc5a612955aa3a2fddb57e) Change-Id: I14c489b3f8af5ebcbfa155a03f0c175e9558ac46 BUG: 1332162 Signed-off-by: Anoop C S Reviewed-on: http://review.gluster.org/14149 Smoke: Gluster Build System NetBSD-regression: NetBSD Build System Reviewed-by: Niels de Vos CentOS-regression: Gluster Build System --- tests/features/mandatory-lock-forced.c | 138 +++++++++++++++++++++++++++++++++ tests/features/mandatory-lock-forced.t | 80 +++++++++++++++++++ 2 files changed, 218 insertions(+) create mode 100644 tests/features/mandatory-lock-forced.c create mode 100644 tests/features/mandatory-lock-forced.t (limited to 'tests') diff --git a/tests/features/mandatory-lock-forced.c b/tests/features/mandatory-lock-forced.c new file mode 100644 index 00000000000..f37206845f1 --- /dev/null +++ b/tests/features/mandatory-lock-forced.c @@ -0,0 +1,138 @@ +#include +#include +#include +#include +#include +#include +#include + +#define LOG_ERR(func, err) do { \ + fprintf (stderr, "%s : returned error (%s)\n", func, strerror(err)); \ + exit (err); \ +} while (0) + +int fd; +struct flock lock; +char *buf = "ten bytes!"; +char *fname = "/mnt/glusterfs/0/mand.lock"; +int open_flags, child, err, status, blocked = 0; + +int do_child (char *argv[]) { + /* Initialize file open flags */ + if (strcmp (argv[2], "BLOCK") == 0) + open_flags = O_RDWR; + else if (strcmp (argv[2], "TRUNC") == 0) + open_flags = O_RDWR | O_TRUNC | O_NONBLOCK; + else if (strcmp (argv[2], "NONE") == 0) + open_flags = O_RDWR | O_NONBLOCK; + else + LOG_ERR ("Invalid option:", EINVAL); + + /* Open the file */ + fd = open (fname, open_flags); + if (fd == -1) + LOG_ERR ("Child open", errno); + + /* Perform the file operation*/ + if (strcmp (argv[3], "READ") == 0) { + buf = NULL; + err = read (fd, buf, 10); + if (err == -1) + LOG_ERR ("Child read", errno); + } else if (strcmp (argv[3], "WRITE") == 0) { + err = write (fd, buf, 10); + if (err == -1) + LOG_ERR ("Child write", errno); + } else if (strcmp (argv[3], "FTRUNCATE") == 0) { + err = ftruncate (fd, 5); + if (err) + LOG_ERR ("Child ftruncate", errno); + } else + LOG_ERR ("Invalid operation:", EINVAL); + + /* Close child fd */ + err = close (fd); + if (err) + LOG_ERR ("Child close", errno); + + /* Exit success */ + exit (0); +} + +int main (int argc, char *argv[]) { + if (argc < 4) { + fprintf (stderr, "Wrong usage: Use as ./mandatory-lock " + " " + "