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

2014-05-24 Thread Michael Kerrisk (man-pages)
On 05/23/2014 05:57 PM, Ondřej Bílka wrote:
> On Sat, May 03, 2014 at 09:33:24AM -0400, Jeff Layton wrote:
>> 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
>>
>>  * sysdeps/unix/sysv/linux/bits/fcntl-linux.h:
>>(F_OFD_GETLK, F_OFD_SETLK, F_OFD_SETLKW): New macros.
>>
>  manual/examples/ofdlocks.c entry is missing.
>  
> Otherwise ok for me, Carlos, Michael do you have additional comments?
> .

After commenting quite extensively on two or three previous rounds of 
the patches, I have no further comments. (Jeff integrated/responded 
to all my comments).

Cheers,

Michael

-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


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

2014-05-24 Thread Michael Kerrisk (man-pages)
On 05/23/2014 05:57 PM, Ondřej Bílka wrote:
 On Sat, May 03, 2014 at 09:33:24AM -0400, Jeff Layton wrote:
 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

  * sysdeps/unix/sysv/linux/bits/fcntl-linux.h:
(F_OFD_GETLK, F_OFD_SETLK, F_OFD_SETLKW): New macros.

  manual/examples/ofdlocks.c entry is missing.
  
 Otherwise ok for me, Carlos, Michael do you have additional comments?
 .

After commenting quite extensively on two or three previous rounds of 
the patches, I have no further comments. (Jeff integrated/responded 
to all my comments).

Cheers,

Michael

-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


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

2014-05-23 Thread Ondřej Bílka
On Sat, May 03, 2014 at 09:33:24AM -0400, Jeff Layton wrote:
> 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
> 
>   * sysdeps/unix/sysv/linux/bits/fcntl-linux.h:
> (F_OFD_GETLK, F_OFD_SETLK, F_OFD_SETLKW): New macros.
>
 manual/examples/ofdlocks.c entry is missing.
 
Otherwise ok for me, Carlos, Michael do you have additional comments?
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


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

2014-05-23 Thread Jeff Layton
On Fri, 23 May 2014 17:57:47 +0200
Ondřej Bílka  wrote:

> On Sat, May 03, 2014 at 09:33:24AM -0400, Jeff Layton wrote:
> > 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
> > 
> > * sysdeps/unix/sysv/linux/bits/fcntl-linux.h:
> >   (F_OFD_GETLK, F_OFD_SETLK, F_OFD_SETLKW): New macros.
> >
>  manual/examples/ofdlocks.c entry is missing.
>  

Oops! Can one of you fix that up, or do you need me to resend?

> Otherwise ok for me, Carlos, Michael do you have additional comments?

-- 
Jeff Layton 
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


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

2014-05-23 Thread Jeff Layton
On Fri, 23 May 2014 17:57:47 +0200
Ondřej Bílka nel...@seznam.cz wrote:

 On Sat, May 03, 2014 at 09:33:24AM -0400, Jeff Layton wrote:
  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
  
  * sysdeps/unix/sysv/linux/bits/fcntl-linux.h:
(F_OFD_GETLK, F_OFD_SETLK, F_OFD_SETLKW): New macros.
 
  manual/examples/ofdlocks.c entry is missing.
  

Oops! Can one of you fix that up, or do you need me to resend?

 Otherwise ok for me, Carlos, Michael do you have additional comments?

-- 
Jeff Layton jlay...@poochiereds.net
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


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

2014-05-23 Thread Ondřej Bílka
On Sat, May 03, 2014 at 09:33:24AM -0400, Jeff Layton wrote:
 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
 
   * sysdeps/unix/sysv/linux/bits/fcntl-linux.h:
 (F_OFD_GETLK, F_OFD_SETLK, F_OFD_SETLKW): New macros.

 manual/examples/ofdlocks.c entry is missing.
 
Otherwise ok for me, Carlos, Michael do you have additional comments?
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


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

2014-05-03 Thread 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

* 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 description instead of the process.  @xref{Open File Description 
Locks}.
+
 The remaining @code{fcntl} commands are 

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

2014-05-03 Thread 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  jlay...@poochiereds.net

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

* 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 the process.
+There is also a different type of record lock that is associated with the
+open file description instead of the process.