Re: [PATCH resend #4] fcntl-linux.h: add new definitions and manual updates for open file description locks

2014-06-26 Thread Michael Kerrisk (man-pages)
On 06/26/2014 09:57 PM, Jeff Layton wrote:
> From: Jeff Layton 
> 
> Open file description locks have been merged into the Linux kernel for
> v3.15.  Add the appropriate command-value definitions and an update to
> the manual that describes their usage.

What's the hold-up here? Jeff's patches have been reviewed by at least
me and Carlos. It'd be nice if they made it in before the 2.20 code freeze...

Cheers,

Michael


> ChangeLog:
> 
> 2014-04-24  Jeff Layton  
> 
>   [BZ#16839]
>   * manual/llio.texi: add section about open file description locks
> 
>   * manual/examples/ofdlocks.c:
> example of open file description lock usage
> 
>   * sysdeps/unix/sysv/linux/bits/fcntl-linux.h:
> (F_OFD_GETLK, F_OFD_SETLK, F_OFD_SETLKW): New macros.
> ---
>  manual/examples/ofdlocks.c |  77 +
>  manual/llio.texi   | 241 
> -
>  sysdeps/unix/sysv/linux/bits/fcntl-linux.h |  17 ++
>  3 files changed, 332 insertions(+), 3 deletions(-)
>  create mode 100644 manual/examples/ofdlocks.c
> 
> diff --git a/manual/examples/ofdlocks.c b/manual/examples/ofdlocks.c
> new file mode 100644
> index ..85e193cdabe6
> --- /dev/null
> +++ b/manual/examples/ofdlocks.c
> @@ -0,0 +1,77 @@
> +/* Open File Description Locks Usage Example
> +   Copyright (C) 1991-2014 Free Software Foundation, Inc.
> +
> +   This program is free software; you can redistribute it and/or
> +   modify it under the terms of the GNU General Public License
> +   as published by the Free Software Foundation; either version 2
> +   of the License, or (at your option) any later version.
> +
> +   This program is distributed in the hope that it will be useful,
> +   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +   GNU General Public License for more details.
> +
> +   You should have received a copy of the GNU General Public License
> +   along with this program; if not, see .
> +*/
> +
> +#define _GNU_SOURCE
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define FILENAME "/tmp/foo"
> +#define NUM_THREADS  3
> +#define ITERATIONS   5
> +
> +void *
> +thread_start (void *arg)
> +{
> +  int i, fd, len;
> +  long tid = (long) arg;
> +  char buf[256];
> +  struct flock lck = {
> +.l_whence = SEEK_SET,
> +.l_start = 0,
> +.l_len = 1,
> +  };
> +
> +  fd = open ("/tmp/foo", O_RDWR | O_CREAT, 0666);
> +
> +  for (i = 0; i < ITERATIONS; i++)
> +{
> +  lck.l_type = F_WRLCK;
> +  fcntl (fd, F_OFD_SETLKW, );
> +
> +  len = sprintf (buf, "%d: tid=%ld fd=%d\n", i, tid, fd);
> +
> +  lseek (fd, 0, SEEK_END);
> +  write (fd, buf, len);
> +  fsync (fd);
> +
> +  lck.l_type = F_UNLCK;
> +  fcntl (fd, F_OFD_SETLK, );
> +
> +  /* sleep to ensure lock is yielded to another thread */
> +  usleep (1);
> +}
> +  pthread_exit (NULL);
> +}
> +
> +int
> +main (int argc, char **argv)
> +{
> +  long i;
> +  pthread_t threads[NUM_THREADS];
> +
> +  truncate (FILENAME, 0);
> +
> +  for (i = 0; i < NUM_THREADS; i++)
> +pthread_create ([i], NULL, thread_start, (void *) i);
> +
> +  pthread_exit (NULL);
> +  return 0;
> +}
> diff --git a/manual/llio.texi b/manual/llio.texi
> index 6f8adfc607d7..864060dc7140 100644
> --- a/manual/llio.texi
> +++ b/manual/llio.texi
> @@ -57,6 +57,10 @@ directly.)
>   flags associated with open files.
>  * File Locks::  Fcntl commands for implementing
>   file locking.
> +* Open File Description Locks:: Fcntl commands for implementing
> + open file description locking.
> +* Open File Description Locks Example:: An example of open file description 
> lock
> + usage
>  * Interrupt Input:: Getting an asynchronous signal when
>   input arrives.
>  * IOCTLs::  Generic I/O Control operations.
> @@ -2890,7 +2894,7 @@ Get flags associated with the open file.  @xref{File 
> Status Flags}.
>  Set flags associated with the open file.  @xref{File Status Flags}.
>  
>  @item F_GETLK
> -Get a file lock.  @xref{File Locks}.
> +Test a file lock.  @xref{File Locks}.
>  
>  @item F_SETLK
>  Set or clear a file lock.  @xref{File Locks}.
> @@ -2898,6 +2902,18 @@ Set or clear a file lock.  @xref{File Locks}.
>  @item F_SETLKW
>  Like @code{F_SETLK}, but wait for completion.  @xref{File Locks}.
>  
> +@item F_OFD_GETLK
> +Test an open file description lock.  @xref{Open File Description Locks}.
> +Specific to Linux.
> +
> +@item F_OFD_SETLK
> +Set or clear an open file description lock.  @xref{Open File Description 
> Locks}.
> +Specific to Linux.
> +
> +@item F_OFD_SETLKW
> +Like 

[PATCH resend #4] fcntl-linux.h: add new definitions and manual updates for open file description locks

2014-06-26 Thread Jeff Layton
From: Jeff Layton 

Open file description locks have been merged into the Linux kernel for
v3.15.  Add the appropriate command-value definitions and an update to
the manual that describes their usage.

ChangeLog:

2014-04-24  Jeff Layton  

[BZ#16839]
* manual/llio.texi: add section about open file description locks

* manual/examples/ofdlocks.c:
  example of open file description lock usage

* sysdeps/unix/sysv/linux/bits/fcntl-linux.h:
  (F_OFD_GETLK, F_OFD_SETLK, F_OFD_SETLKW): New macros.
---
 manual/examples/ofdlocks.c |  77 +
 manual/llio.texi   | 241 -
 sysdeps/unix/sysv/linux/bits/fcntl-linux.h |  17 ++
 3 files changed, 332 insertions(+), 3 deletions(-)
 create mode 100644 manual/examples/ofdlocks.c

diff --git a/manual/examples/ofdlocks.c b/manual/examples/ofdlocks.c
new file mode 100644
index ..85e193cdabe6
--- /dev/null
+++ b/manual/examples/ofdlocks.c
@@ -0,0 +1,77 @@
+/* Open File Description Locks Usage Example
+   Copyright (C) 1991-2014 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   as published by the Free Software Foundation; either version 2
+   of the License, or (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see .
+*/
+
+#define _GNU_SOURCE
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define FILENAME   "/tmp/foo"
+#define NUM_THREADS3
+#define ITERATIONS 5
+
+void *
+thread_start (void *arg)
+{
+  int i, fd, len;
+  long tid = (long) arg;
+  char buf[256];
+  struct flock lck = {
+.l_whence = SEEK_SET,
+.l_start = 0,
+.l_len = 1,
+  };
+
+  fd = open ("/tmp/foo", O_RDWR | O_CREAT, 0666);
+
+  for (i = 0; i < ITERATIONS; i++)
+{
+  lck.l_type = F_WRLCK;
+  fcntl (fd, F_OFD_SETLKW, );
+
+  len = sprintf (buf, "%d: tid=%ld fd=%d\n", i, tid, fd);
+
+  lseek (fd, 0, SEEK_END);
+  write (fd, buf, len);
+  fsync (fd);
+
+  lck.l_type = F_UNLCK;
+  fcntl (fd, F_OFD_SETLK, );
+
+  /* sleep to ensure lock is yielded to another thread */
+  usleep (1);
+}
+  pthread_exit (NULL);
+}
+
+int
+main (int argc, char **argv)
+{
+  long i;
+  pthread_t threads[NUM_THREADS];
+
+  truncate (FILENAME, 0);
+
+  for (i = 0; i < NUM_THREADS; i++)
+pthread_create ([i], NULL, thread_start, (void *) i);
+
+  pthread_exit (NULL);
+  return 0;
+}
diff --git a/manual/llio.texi b/manual/llio.texi
index 6f8adfc607d7..864060dc7140 100644
--- a/manual/llio.texi
+++ b/manual/llio.texi
@@ -57,6 +57,10 @@ directly.)
  flags associated with open files.
 * File Locks::  Fcntl commands for implementing
  file locking.
+* Open File Description Locks:: Fcntl commands for implementing
+ open file description locking.
+* Open File Description Locks Example:: An example of open file description 
lock
+ usage
 * Interrupt Input:: Getting an asynchronous signal when
  input arrives.
 * IOCTLs::  Generic I/O Control operations.
@@ -2890,7 +2894,7 @@ Get flags associated with the open file.  @xref{File 
Status Flags}.
 Set flags associated with the open file.  @xref{File Status Flags}.
 
 @item F_GETLK
-Get a file lock.  @xref{File Locks}.
+Test a file lock.  @xref{File Locks}.
 
 @item F_SETLK
 Set or clear a file lock.  @xref{File Locks}.
@@ -2898,6 +2902,18 @@ Set or clear a file lock.  @xref{File Locks}.
 @item F_SETLKW
 Like @code{F_SETLK}, but wait for completion.  @xref{File Locks}.
 
+@item F_OFD_GETLK
+Test an open file description lock.  @xref{Open File Description Locks}.
+Specific to Linux.
+
+@item F_OFD_SETLK
+Set or clear an open file description lock.  @xref{Open File Description 
Locks}.
+Specific to Linux.
+
+@item F_OFD_SETLKW
+Like @code{F_OFD_SETLK}, but block until lock is acquired.
+@xref{Open File Description Locks}.  Specific to Linux.
+
 @item F_GETOWN
 Get process or process group ID to receive @code{SIGIO} signals.
 @xref{Interrupt Input}.
@@ -3576,6 +3592,10 @@ set_nonblock_flag (int desc, int value)
 
 @cindex file locks
 @cindex record locking
+This section describes record locks that are associated with the process.
+There is also a different type of record lock that is associated with the
+open file 

[PATCH resend #4] fcntl-linux.h: add new definitions and manual updates for open file description locks

2014-06-26 Thread Jeff Layton
From: Jeff Layton jlay...@poochiereds.net

Open file description locks have been merged into the Linux kernel for
v3.15.  Add the appropriate command-value definitions and an update to
the manual that describes their usage.

ChangeLog:

2014-04-24  Jeff Layton  jlay...@poochiereds.net

[BZ#16839]
* manual/llio.texi: add section about open file description locks

* manual/examples/ofdlocks.c:
  example of open file description lock usage

* sysdeps/unix/sysv/linux/bits/fcntl-linux.h:
  (F_OFD_GETLK, F_OFD_SETLK, F_OFD_SETLKW): New macros.
---
 manual/examples/ofdlocks.c |  77 +
 manual/llio.texi   | 241 -
 sysdeps/unix/sysv/linux/bits/fcntl-linux.h |  17 ++
 3 files changed, 332 insertions(+), 3 deletions(-)
 create mode 100644 manual/examples/ofdlocks.c

diff --git a/manual/examples/ofdlocks.c b/manual/examples/ofdlocks.c
new file mode 100644
index ..85e193cdabe6
--- /dev/null
+++ b/manual/examples/ofdlocks.c
@@ -0,0 +1,77 @@
+/* Open File Description Locks Usage Example
+   Copyright (C) 1991-2014 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License
+   as published by the Free Software Foundation; either version 2
+   of the License, or (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see http://www.gnu.org/licenses/.
+*/
+
+#define _GNU_SOURCE
+#include stdio.h
+#include sys/types.h
+#include sys/stat.h
+#include unistd.h
+#include fcntl.h
+#include pthread.h
+
+#define FILENAME   /tmp/foo
+#define NUM_THREADS3
+#define ITERATIONS 5
+
+void *
+thread_start (void *arg)
+{
+  int i, fd, len;
+  long tid = (long) arg;
+  char buf[256];
+  struct flock lck = {
+.l_whence = SEEK_SET,
+.l_start = 0,
+.l_len = 1,
+  };
+
+  fd = open (/tmp/foo, O_RDWR | O_CREAT, 0666);
+
+  for (i = 0; i  ITERATIONS; i++)
+{
+  lck.l_type = F_WRLCK;
+  fcntl (fd, F_OFD_SETLKW, lck);
+
+  len = sprintf (buf, %d: tid=%ld fd=%d\n, i, tid, fd);
+
+  lseek (fd, 0, SEEK_END);
+  write (fd, buf, len);
+  fsync (fd);
+
+  lck.l_type = F_UNLCK;
+  fcntl (fd, F_OFD_SETLK, lck);
+
+  /* sleep to ensure lock is yielded to another thread */
+  usleep (1);
+}
+  pthread_exit (NULL);
+}
+
+int
+main (int argc, char **argv)
+{
+  long i;
+  pthread_t threads[NUM_THREADS];
+
+  truncate (FILENAME, 0);
+
+  for (i = 0; i  NUM_THREADS; i++)
+pthread_create (threads[i], NULL, thread_start, (void *) i);
+
+  pthread_exit (NULL);
+  return 0;
+}
diff --git a/manual/llio.texi b/manual/llio.texi
index 6f8adfc607d7..864060dc7140 100644
--- a/manual/llio.texi
+++ b/manual/llio.texi
@@ -57,6 +57,10 @@ directly.)
  flags associated with open files.
 * File Locks::  Fcntl commands for implementing
  file locking.
+* Open File Description Locks:: Fcntl commands for implementing
+ open file description locking.
+* Open File Description Locks Example:: An example of open file description 
lock
+ usage
 * Interrupt Input:: Getting an asynchronous signal when
  input arrives.
 * IOCTLs::  Generic I/O Control operations.
@@ -2890,7 +2894,7 @@ Get flags associated with the open file.  @xref{File 
Status Flags}.
 Set flags associated with the open file.  @xref{File Status Flags}.
 
 @item F_GETLK
-Get a file lock.  @xref{File Locks}.
+Test a file lock.  @xref{File Locks}.
 
 @item F_SETLK
 Set or clear a file lock.  @xref{File Locks}.
@@ -2898,6 +2902,18 @@ Set or clear a file lock.  @xref{File Locks}.
 @item F_SETLKW
 Like @code{F_SETLK}, but wait for completion.  @xref{File Locks}.
 
+@item F_OFD_GETLK
+Test an open file description lock.  @xref{Open File Description Locks}.
+Specific to Linux.
+
+@item F_OFD_SETLK
+Set or clear an open file description lock.  @xref{Open File Description 
Locks}.
+Specific to Linux.
+
+@item F_OFD_SETLKW
+Like @code{F_OFD_SETLK}, but block until lock is acquired.
+@xref{Open File Description Locks}.  Specific to Linux.
+
 @item F_GETOWN
 Get process or process group ID to receive @code{SIGIO} signals.
 @xref{Interrupt Input}.
@@ -3576,6 +3592,10 @@ set_nonblock_flag (int desc, int value)
 
 @cindex file locks
 @cindex record locking
+This section describes record locks that are associated with 

Re: [PATCH resend #4] fcntl-linux.h: add new definitions and manual updates for open file description locks

2014-06-26 Thread Michael Kerrisk (man-pages)
On 06/26/2014 09:57 PM, Jeff Layton wrote:
 From: Jeff Layton jlay...@poochiereds.net
 
 Open file description locks have been merged into the Linux kernel for
 v3.15.  Add the appropriate command-value definitions and an update to
 the manual that describes their usage.

What's the hold-up here? Jeff's patches have been reviewed by at least
me and Carlos. It'd be nice if they made it in before the 2.20 code freeze...

Cheers,

Michael


 ChangeLog:
 
 2014-04-24  Jeff Layton  jlay...@poochiereds.net
 
   [BZ#16839]
   * manual/llio.texi: add section about open file description locks
 
   * manual/examples/ofdlocks.c:
 example of open file description lock usage
 
   * sysdeps/unix/sysv/linux/bits/fcntl-linux.h:
 (F_OFD_GETLK, F_OFD_SETLK, F_OFD_SETLKW): New macros.
 ---
  manual/examples/ofdlocks.c |  77 +
  manual/llio.texi   | 241 
 -
  sysdeps/unix/sysv/linux/bits/fcntl-linux.h |  17 ++
  3 files changed, 332 insertions(+), 3 deletions(-)
  create mode 100644 manual/examples/ofdlocks.c
 
 diff --git a/manual/examples/ofdlocks.c b/manual/examples/ofdlocks.c
 new file mode 100644
 index ..85e193cdabe6
 --- /dev/null
 +++ b/manual/examples/ofdlocks.c
 @@ -0,0 +1,77 @@
 +/* Open File Description Locks Usage Example
 +   Copyright (C) 1991-2014 Free Software Foundation, Inc.
 +
 +   This program is free software; you can redistribute it and/or
 +   modify it under the terms of the GNU General Public License
 +   as published by the Free Software Foundation; either version 2
 +   of the License, or (at your option) any later version.
 +
 +   This program is distributed in the hope that it will be useful,
 +   but WITHOUT ANY WARRANTY; without even the implied warranty of
 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 +   GNU General Public License for more details.
 +
 +   You should have received a copy of the GNU General Public License
 +   along with this program; if not, see http://www.gnu.org/licenses/.
 +*/
 +
 +#define _GNU_SOURCE
 +#include stdio.h
 +#include sys/types.h
 +#include sys/stat.h
 +#include unistd.h
 +#include fcntl.h
 +#include pthread.h
 +
 +#define FILENAME /tmp/foo
 +#define NUM_THREADS  3
 +#define ITERATIONS   5
 +
 +void *
 +thread_start (void *arg)
 +{
 +  int i, fd, len;
 +  long tid = (long) arg;
 +  char buf[256];
 +  struct flock lck = {
 +.l_whence = SEEK_SET,
 +.l_start = 0,
 +.l_len = 1,
 +  };
 +
 +  fd = open (/tmp/foo, O_RDWR | O_CREAT, 0666);
 +
 +  for (i = 0; i  ITERATIONS; i++)
 +{
 +  lck.l_type = F_WRLCK;
 +  fcntl (fd, F_OFD_SETLKW, lck);
 +
 +  len = sprintf (buf, %d: tid=%ld fd=%d\n, i, tid, fd);
 +
 +  lseek (fd, 0, SEEK_END);
 +  write (fd, buf, len);
 +  fsync (fd);
 +
 +  lck.l_type = F_UNLCK;
 +  fcntl (fd, F_OFD_SETLK, lck);
 +
 +  /* sleep to ensure lock is yielded to another thread */
 +  usleep (1);
 +}
 +  pthread_exit (NULL);
 +}
 +
 +int
 +main (int argc, char **argv)
 +{
 +  long i;
 +  pthread_t threads[NUM_THREADS];
 +
 +  truncate (FILENAME, 0);
 +
 +  for (i = 0; i  NUM_THREADS; i++)
 +pthread_create (threads[i], NULL, thread_start, (void *) i);
 +
 +  pthread_exit (NULL);
 +  return 0;
 +}
 diff --git a/manual/llio.texi b/manual/llio.texi
 index 6f8adfc607d7..864060dc7140 100644
 --- a/manual/llio.texi
 +++ b/manual/llio.texi
 @@ -57,6 +57,10 @@ directly.)
   flags associated with open files.
  * File Locks::  Fcntl commands for implementing
   file locking.
 +* Open File Description Locks:: Fcntl commands for implementing
 + open file description locking.
 +* Open File Description Locks Example:: An example of open file description 
 lock
 + usage
  * Interrupt Input:: Getting an asynchronous signal when
   input arrives.
  * IOCTLs::  Generic I/O Control operations.
 @@ -2890,7 +2894,7 @@ Get flags associated with the open file.  @xref{File 
 Status Flags}.
  Set flags associated with the open file.  @xref{File Status Flags}.
  
  @item F_GETLK
 -Get a file lock.  @xref{File Locks}.
 +Test a file lock.  @xref{File Locks}.
  
  @item F_SETLK
  Set or clear a file lock.  @xref{File Locks}.
 @@ -2898,6 +2902,18 @@ Set or clear a file lock.  @xref{File Locks}.
  @item F_SETLKW
  Like @code{F_SETLK}, but wait for completion.  @xref{File Locks}.
  
 +@item F_OFD_GETLK
 +Test an open file description lock.  @xref{Open File Description Locks}.
 +Specific to Linux.
 +
 +@item F_OFD_SETLK
 +Set or clear an open file description lock.  @xref{Open File Description 
 Locks}.
 +Specific to Linux.
 +
 +@item F_OFD_SETLKW
 +Like @code{F_OFD_SETLK}, but block until lock is