[PATCH hurd 0/6] Add file record locking support
Hi, Attached in subsequent mails is a patch series for file record locking support, mainly developed by Neal Walfield in 2001. The patch was published by Marcus Brinkmann and later re-diffed by Michael Banck in 2002. Now modified to use libpthread instead of cthreads and some additional fixes. Links: http://savannah.gnu.org/task/?1022 http://savannah.gnu.org/patch/?332 I've run this patched Hurd on several kvm images since July 2014 without problems. 1/6: hurd_new_RPC.patch: add new RPC: file_record_lock 2/6: libdiskfs_file_record_lock.patch: implement diskfs_S_file_record_lock and modify diskfs_S_* accordingly, initialize and release lock_status. 3/6: libfshelp_rlock.patch: implement fshelp_rlock_* functions 4/6: libfshelp-tests_rlock.patch: implement file_record_lock tests 5/6: libnetfs_file_record_lock.patch: implement netfs_S_file_record_lock 6/6: libtrivfs_file_record_lock.patch: implement trivfs_S_file_record_lock There are two issues left to solve: 1) l_pid of struct flock is not set. According to the manpage (and posix) the PID of the process blocking the lock should be reported. Can maybe be solved by a shared memory solution in glibc or as indicated in task 1022. 2) fork(2) does not create a process without the locks set for the child. According to the fcntl(2) manpage (and posix) record locks are not inherited by a child created via fork(2). The fork functionality is tested in the program libfshelp-tests/fork.c. Proposed solutions are mentioned in task 1022. (This is probably the main cause tdbtorture in tdb does not work well with the current file record locking patches.) Maybe also the copyright text should be updated to a more modern version for new files (and adding copyright year 2015?) Thanks! -- To UNSUBSCRIBE, email to debian-hurd-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: https://lists.debian.org/1420716485.2983.117.ca...@g3620.my.own.domain
[PATCH hurd 2/6] Add file record locking support
libdiskfs: implement diskfs_S_file_record_lock and modify diskfs_S_* accordingly, initialize and release lock_status libdiskfs/ChangeLog 2014-08-21 Svante Signell * define temporary CPP_FLAGS until glibc is updated * file-lock-stat.c: Port from cthreads to libpthread. * file-lock.c: Likewise * file-record-lock: Likewise 2001-04-11 Neal H Walfield * Makefile (FSSRCS): Add file-record-lock.c. * diskfs.h (struct peropen): Change the type of lock_status from an int to a struct rlock_peropen. (struct node): Change the type of userbox from a struct lock_box to a struct rlock_box. * dir-lookup.c (diskfs_S_dir_lookup): Use fshelp_tweak_rlock as fshelp_acquire_lock is now depreciated. * file-lock-stat.c (diskfs_S_file_lock_stat): Total rewrite around the new record locking functions. * file-lock.c (diskfs_S_file_lock): Total rewrite around the new record locking functions. * file-record-lock.c: New file. Implement diskfs_S_file_record_lock. * node-make.c (diskfs_make_node): Initialize userbox with fshelp_rlock_init. * peropen-make.c (diskfs_make_peropen): Initialize lock_status using fshelp_rlock_po_init. * peropen-rele.c (diskfs_release_peropen): Release lock_status using fshelp_rlock_drop_peropen. Index: hurd-0.5.git20141210/libdiskfs/Makefile === --- hurd-0.5.git20141210.orig/libdiskfs/Makefile +++ hurd-0.5.git20141210/libdiskfs/Makefile @@ -26,7 +26,8 @@ FSSRCS= dir-chg.c dir-link.c dir-lookup. file-get-trans.c file-get-transcntl.c file-getcontrol.c \ file-getfh.c file-getlinknode.c file-lock-stat.c \ file-lock.c file-set-size.c file-set-trans.c file-statfs.c \ - file-sync.c file-syncfs.c file-utimes.c file-reparent.c + file-sync.c file-syncfs.c file-utimes.c file-record-lock.c \ + file-reparent.c IOSRCS= io-async-icky.c io-async.c io-duplicate.c io-get-conch.c io-revoke.c \ io-map-cntl.c io-map.c io-modes-get.c io-modes-off.c \ io-modes-on.c io-modes-set.c io-owner-mod.c io-owner-get.c \ @@ -72,4 +73,10 @@ ifsock-MIGSFLAGS = -imacros $(srcdir)/fs exec_startup-MIGSFLAGS = -imacros $(srcdir)/fsmutations.h MIGCOMSFLAGS = -prefix diskfs_ +# Define the 64 bit versions of the second argument to fcntl() +# Can safely be removed when glibc is updated +EXTRA_CPP_FLAGS= -DF_GETLK64=10 -DF_SETLK64=11 -DF_SETLKW64=12 +dir-lookup-CPPFLAGS += $(EXTRA_CPP_FLAGS) +file-lock-CPPFLAGS += $(EXTRA_CPP_FLAGS) + include ../Makeconf Index: hurd-0.5.git20141210/libdiskfs/diskfs.h === --- hurd-0.5.git20141210.orig/libdiskfs/diskfs.h +++ hurd-0.5.git20141210/libdiskfs/diskfs.h @@ -56,8 +56,8 @@ struct protid /* One of these is created for each node opened by dir_lookup. */ struct peropen { - off_t filepointer; - int lock_status; + loff_t filepointer; + struct rlock_peropen lock_status; refcount_t refcnt; int openstat; @@ -105,7 +105,7 @@ struct node struct transbox transbox; - struct lock_box userlock; + struct rlock_box userlock; struct conch conch; Index: hurd-0.5.git20141210/libdiskfs/dir-lookup.c === --- hurd-0.5.git20141210.orig/libdiskfs/dir-lookup.c +++ hurd-0.5.git20141210/libdiskfs/dir-lookup.c @@ -517,12 +517,27 @@ diskfs_S_dir_lookup (struct protid *dirc if (! error) { newpo = 0; + struct flock64 lock = +{ + l_start: 0, + l_len: 0, + l_whence: SEEK_SET + }; + if (flags & O_EXLOCK) - error = fshelp_acquire_lock (&np->userlock, &newpi->po->lock_status, - &np->lock, LOCK_EX); +{ + lock.l_type = F_WRLCK; + error = fshelp_rlock_tweak (&np->userlock, &np->lock, + &newpi->po->lock_status, flags, 0, 0, + F_SETLK64, &lock); + } else if (flags & O_SHLOCK) - error = fshelp_acquire_lock (&np->userlock, &newpi->po->lock_status, - &np->lock, LOCK_SH); +{ + lock.l_type = F_RDLCK; + error = fshelp_rlock_tweak (&np->userlock, &np->lock, + &newpi->po->lock_status, flags, 0, 0, + F_SETLK64, &lock); + } } if (! error) Index: hurd-0.5.git20141210/libdiskfs/file-lock-stat.c === --- hurd-0.5.git20141210.orig/libdiskfs/file-lock-stat.c +++ hurd-0.5.git20141210/libdiskfs/file-lock-stat.c @@ -1,38 +1,43 @@ -/* - Copyright (C) 1994, 1995 Free Software Foundation +/* Copyright (C) 2001, 2014 Free Software Foundation, Inc. -This file is part of the GNU Hurd. + Written by Neal H Walfield -The GNU Hurd 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, or (at your option) -any later version. - -Th
[PATCH hurd 1/6] Add file record locking support
hurd: add new RPC: file_record_lock hurd/ChangeLog 2014-08-21 Svante Signell * fs.defs: Added description. * hurd_types.defs: Make struct flock_t seven integers long since l_start and l_len are 64bit. * hurd_types.h: typedef flock_t as flock64. 2001-04-10 Neal H Walfield * fs.defs: New rpc file_record_lock. * hurd_types.defs: Import . Index: hurd-0.5.git20141210/hurd/fs.defs === --- hurd-0.5.git20141210.orig/hurd/fs.defs +++ hurd-0.5.git20141210/hurd/fs.defs @@ -373,3 +373,12 @@ routine file_get_source ( file: file_t; RPT out source: string_t); + +/* Do fcntl type locking on FILE. CMD is from the set + F_GETLK64, F_SETLK64, F_SETLKW64. FLOCK64 is passed + by the user and is as defined by . */ +routine file_record_lock ( + file: file_t; + RPT + cmd: int; + inout flock64: flock_t); Index: hurd-0.5.git20141210/hurd/hurd_types.defs === --- hurd-0.5.git20141210.orig/hurd/hurd_types.defs +++ hurd-0.5.git20141210/hurd/hurd_types.defs @@ -372,7 +372,7 @@ type idarray_t = array[] of uid_t; type rusage_t = struct[18] of int; /* XXX */ -type flock_t = struct[5] of int; +type flock_t = struct[7] of int; /* l_start and l_len are 64 bit */ type timespec_t = struct[2] of int; @@ -386,3 +386,5 @@ import ; import ; import ; import ; +import ; + Index: hurd-0.5.git20141210/hurd/hurd_types.h === --- hurd-0.5.git20141210.orig/hurd/hurd_types.h +++ hurd-0.5.git20141210/hurd/hurd_types.h @@ -65,7 +65,7 @@ typedef pid_t *pidarray_t; typedef uid_t *idarray_t; typedef loff_t *off_array_t; typedef struct rusage rusage_t; -typedef struct flock flock_t; +typedef struct flock64 flock_t; typedef struct utsname utsname_t; #if _FILE_OFFSET_BITS == 64 typedef struct stat io_statbuf_t;
[PATCH hurd 3/6] Add file record locking support
libfshelp: implement fshelp_rlock_* functions libfshelp/ChangeLog 2014-08-21 Svante Signell * Makefile: Link with pthread * define temporary CPP_FLAGS until glibc is updated * rlock-drop-peropen.c: Port from cthreads to libpthread. * rlock-tweak.c: Likewise * fshelp.h: Likewise * rlock.h: Likewise * FIXME: remove FIXMEs 2001-04-12 Neal H Walfield * fshelp.h (struct rlock_box): New structure. (struct rlock_peropen): Likewise. (fshelp_rlock_init): New funtion. (fshelp_rlock_po_init): Likewise. (fshelp_rlock_drop_peropen): Likewise. (fshelp_rlock_tweak): Likewise. (fshelp_rlock_peropen_status): Likewise. (fshelp_rlock_node_status): Likewise. * rlock-drop-peropen.c: New file. Implement fshelp_rlock_drop_peropen. * rlock-status.c: New file. Implement fshelp_rlock_peropen_status and fshelp_rlock_node_status. * rlock-tweak.c: New file. Implement fshelp_rlock_tweak. * rlock.h: New file. * extern-inline.c: New file. * Makefile (LCLHDRS): Add rlock.h. (SRCS): Add extern-inline.c, rlock-drop-peropen.c, rlock-tweak.c and rlock-status.c. Index: hurd-0.5.git20141210/libfshelp/Makefile === --- hurd-0.5.git20141210.orig/libfshelp/Makefile +++ hurd-0.5.git20141210/libfshelp/Makefile @@ -30,11 +30,19 @@ SRCS = lock-acquire.c lock-init.c \ get-identity.c \ perms-isowner.c perms-iscontroller.c perms-access.c \ perms-checkdirmod.c \ - touch.c -installhdrs = fshelp.h + touch.c \ + extern-inline.c \ + rlock-drop-peropen.c rlock-tweak.c rlock-status.c + +installhdrs = fshelp.h locks.h trans.h rlock.h HURDLIBS = shouldbeinlibc iohelp ports ihash LDLIBS += -lpthread OBJS = $(subst .c,.o,$(SRCS)) +# Define the 64 bit versions of the second argument to fcntl() +# Can safely be removed when glibc is updated +EXTRA_CPP_FLAGS= -DF_GETLK64=10 -DF_SETLK64=11 -DF_SETLKW64=12 +rlock-tweak-CPPFLAGS += $(EXTRA_CPP_FLAGS) + include ../Makeconf Index: hurd-0.5.git20141210/libfshelp/fshelp.h === --- hurd-0.5.git20141210.orig/libfshelp/fshelp.h +++ hurd-0.5.git20141210/libfshelp/fshelp.h @@ -19,18 +19,24 @@ #ifndef _HURD_FSHELP_ #define _HURD_FSHELP_ +#ifndef FSHELP_EXTERN_INLINE +#define FSHELP_EXTERN_INLINE extern inline +#endif + /* This library implements various things that are generic to all or most implementors of the filesystem protocol. It presumes that you are using the iohelp library as well. It is divided into separate facilities which may be used independently. */ #include +#include #include #include #include #include #include #include +#include /* Keeping track of active translators */ @@ -208,7 +214,11 @@ struct lock_box int shcount; }; -/* Call when a user makes a request to acquire an lock via file_lock. +/* Initialize lock_box BOX. (The user int passed to fshelp_acquire_lock + should be initialized with LOCK_UN.). */ +void fshelp_lock_init (struct lock_box *box); + +/* Call when a user makes a request to acquire a lock via file_lock. There should be one lock box per object and one int per open; these are passed as arguments BOX and USER respectively. FLAGS are as per file_lock. MUT is a mutex which will be held whenever this @@ -216,11 +226,71 @@ struct lock_box error_t fshelp_acquire_lock (struct lock_box *box, int *user, pthread_mutex_t *mut, int flags); + +/* Record locking. */ -/* Initialize lock_box BOX. (The user int passed to fshelp_acquire_lock - should be initialized with LOCK_UN.). */ -void fshelp_lock_init (struct lock_box *box); +/* Unique to a node; initialize with fshelp_rlock_init. */ +struct rlock_box +{ + struct rlock_list *locks; /* List of locks on the file. */ +}; + +/* Initialize the rlock_box BOX. */ +FSHELP_EXTERN_INLINE +error_t fshelp_rlock_init (struct rlock_box *box) +{ + box->locks = NULL; + return 0; +} + +/* Unique to a peropen. */ +struct rlock_peropen +{ + /* This is a pointer to a pointer to a rlock_lock (and not a pointer + to a rlock_list) as it really serves two functions: + o the list of locks owned by this peropen + o the unique peropen identifier that all locks on this peropen share. */ + struct rlock_list **locks; +}; + +FSHELP_EXTERN_INLINE +error_t fshelp_rlock_po_init (struct rlock_peropen *po) +{ + po->locks = malloc (sizeof (struct rlock_list *)); + if (! po->locks) +return ENOMEM; + + *po->locks = NULL; + return 0; +} + +/* Release all of the locks held by a given peropen. */ +error_t fshelp_rlock_drop_peropen (struct rlock_peropen *po); + +/* Call when a user makes a request to tweak a lock as via fcntl. There + should be one rlock box per object. BOX is the rlock box associated + with the object. MUT is a mutex which should be held whenever this + routine is called; it should be unique on a pernode basis. PO is the + peropen identifier. OPEN_MODE is how the file was opened
[PATCH hurd 4/6] Add file record locking support
./Makefile: Add sub-directory libfshelp-tests. libfshelp-tests: implement file_record_lock tests ./ChangeLog 2014-08-21 Svante Signell * Makefile: Add sub-directory libfshelp-tests. libfshelp-tests/ChangeLog 2014-08-21 Svante Signell * Makefile: Link with pthread, add build of checklock * define temporary CPP_FLAGS until glibc is updated * checklock.c: New file. * Fix typos in README 2001-04-11 Neal H Walfield * ChangeLog: New file, mentioning itself in this sentence. * Makefile: New file. * README: Likewise. * fork.c: Likewise. * locks: Likewise. * locks-tests: Likewise. * locks.c: Likewise. * race.c: Likewise. Index: hurd-0.5.git20141210/Makefile === --- hurd-0.5.git20141210.orig/Makefile +++ hurd-0.5.git20141210/Makefile @@ -37,7 +37,7 @@ prog-subdirs = auth proc exec term \ storeio pflocal pfinet defpager mach-defpager \ login daemons boot console \ hostmux usermux ftpfs trans \ - console-client utils sutils \ + console-client utils sutils libfshelp-tests \ benchmarks fstests \ random \ procfs \ Index: hurd-0.5.git20141210/libfshelp-tests/Makefile === --- /dev/null +++ hurd-0.5.git20141210/libfshelp-tests/Makefile @@ -0,0 +1,47 @@ +# Makefile libfshelp test cases +# +# Copyright (C) 2001 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, 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, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +dir := libfshelp-tests +makemode := utilities + +targets = race locks fork checklock +SRCS = race.c locks.c fork.c checklock.c + +MIGSTUBS = fsUser.o ioUser.o +OBJS = $(SRCS:.c=.o) $(MIGSTUBS) +HURDLIBS = fshelp ports +LDLIBS += -lpthread + +race: race.o fsUser.o ioUser.o +fork: fork.o fsUser.o +locks: locks.o +checklock: checklock.o fsUser.o + +race locks: ../libfshelp/libfshelp.a ../libports/libports.a \ + ../libthreads/libthreads.a + +# Define the 64 bit versions of the second argument to fcntl() +# Can safely be removed when glibc is updated +EXTRA_CPP_FLAGS= -DF_GETLK64=10 -DF_SETLK64=11 -DF_SETLKW64=12 +fork-CPPFLAGS += $(EXTRA_CPP_FLAGS) +locks-CPPFLAGS += $(EXTRA_CPP_FLAGS) +race-CPPFLAGS += $(EXTRA_CPP_FLAGS) +checklock-CPPFLAGS += $(EXTRA_CPP_FLAGS) + +include ../Makeconf + Index: hurd-0.5.git20141210/libfshelp-tests/README === --- /dev/null +++ hurd-0.5.git20141210/libfshelp-tests/README @@ -0,0 +1,102 @@ +These programs are used to help test the algorithms in the libfshelp +library. + +Record Locking +== + +Race + + +Race locks a file, reads an integer, increments it, writes the result to +the file and then unlocks the file -- 10,000 times. It is intended that +multiple instances of this program be run at the same time. Race takes +three arguments: the file to use, the start of the lock and the length. +For obvious reasons, it is important that all instances of race have +locks that overlap. For example: + + # rm -f foo && ( ./race foo 2 0 & ./race foo 2 3 & \ + > ./race foo 0 3 ) + Was blocked 5482 times + Was blocked 5485 times + Was blocked 5479 times + # cat foo + 3 + +We see here that each process was blocked several thousand times and that +the result in the file foo is 3. Perfect. + +Locks +- + +Locks is an interactive shell that has one ``file'' and ten open file +descriptors. Using some simple commands, one can test to see if locks +are established, cleared, and enforced. The principal command is +`lock,' which takes four parameters. The first is the file descriptor +to lock, the second is the start of the lock, the third is the length of +the lock (0 = until EOF) and the last is the type of lock to establish +from the set {0: F_UNLCK, 1: F_RDLCK, 2: F_WRLCK}. Help on the other +commands can be gotten using the `help' command. + +A small run: + + # ./locks + > lock 0 10 0 1 + 0:Start = 10; Length =0; Type = F_RDLCK + +Lock from byte 10 through the EOF. + + > lock 0 20 0 0 + 0:Start = 10; Length = 10; Type = F_RDLCK + +Unlock from byte 20 through the EOF. + + > lock 0 11 8 2 + 0:Start = 10; Length =1; Type = F_RDLCK + Start = 11; Length =8; Type = F_WRLCK + Start = 19; Length =1; Ty
[PATCH hurd 6/6] Add file record locking support
libtrivfs: implement trivfs_S_file_record_lock libnetfs/ChangeLog 2001-04-11 Neal H Walfield * file-record-lock.c: New file. Implement netfs_S_file_record_lock. * Makefile (SRCS): Add file-record-lock.c Index: hurd-0.5.git20141210/libtrivfs/Makefile === --- hurd-0.5.git20141210.orig/libtrivfs/Makefile +++ hurd-0.5.git20141210/libtrivfs/Makefile @@ -25,7 +25,7 @@ FSSRCS= dir-link.c dir-mkdir.c dir-mkfil file-getlinknode.c file-lock.c file-set-trans.c file-statfs.c \ file-sync.c file-syncfs.c file-set-size.c file-utimes.c file-exec.c \ file-access.c dir-chg.c file-chg.c file-get-storage-info.c \ - file-get-fs-options.c file-reparent.c get-source.c + file-get-fs-options.c file-record-lock.c file-reparent.c get-source.c IOSRCS=io-async-icky.c io-async.c io-duplicate.c io-map.c io-modes-get.c \ io-modes-off.c io-modes-on.c io-modes-set.c io-owner-get.c \ Index: hurd-0.5.git20141210/libtrivfs/file-record-lock.c === --- /dev/null +++ hurd-0.5.git20141210/libtrivfs/file-record-lock.c @@ -0,0 +1,28 @@ +/* + Copyright (C) 2001, 2014 Free Software Foundation + + 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, 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, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ + +#include "priv.h" +#include "trivfs_fs_S.h" + +kern_return_t +trivfs_S_file_record_lock (struct trivfs_protid *cred, + mach_port_t reply, + mach_msg_type_name_t reply_type, + int cmd, struct flock64 *lock) +{ + return EOPNOTSUPP; +}
[PATCH hurd 5/6] Add file record locking support
libnetfs: implement netfs_S_file_record_lock libnetfs/ChangeLog 2001-04-11 Neal H Walfield * file-record-lock.c: New file. Implement netfs_S_file_record_lock. * Makefile (SRCS): Add file-record-lock.c Index: hurd-0.5.git20141210/libnetfs/Makefile === --- hurd-0.5.git20141210.orig/libnetfs/Makefile +++ hurd-0.5.git20141210/libnetfs/Makefile @@ -34,8 +34,8 @@ FSSRCS= dir-link.c dir-lookup.c dir-mkdi file-get-translator.c file-getcontrol.c file-getlinknode.c \ file-lock-stat.c file-lock.c file-set-size.c \ file-set-translator.c file-statfs.c file-sync.c file-syncfs.c \ - file-utimes.c file-reparent.c fsstubs.c file-get-transcntl.c \ - get-source.c + file-utimes.c file-record-lock.c file-reparent.c fsstubs.c \ + file-get-transcntl.c get-source.c IOSRCS= io-read.c io-readable.c io-seek.c io-write.c io-stat.c io-async.c \ io-set-all-openmodes.c io-get-openmodes.c io-set-some-openmodes.c \ @@ -70,7 +70,6 @@ io-MIGSFLAGS = -imacros $(srcdir)/mutati ifsock-MIGSFLAGS = -imacros $(srcdir)/mutations.h MIGCOMSFLAGS = -prefix netfs_ - include ../Makeconf fsysServer.c fsys_S.h fsServer.c fs_S.h ioServer.c io_S.h ifsockServer.c ifsock_S.h: mutations.h Index: hurd-0.5.git20141210/libnetfs/file-record-lock.c === --- /dev/null +++ hurd-0.5.git20141210/libnetfs/file-record-lock.c @@ -0,0 +1,31 @@ +/* + Copyright (C) 2001, 2014 Free Software Foundation, Inc. + + Written by Neal H Walfield + + This file is part of the GNU Hurd. + + The GNU Hurd 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, or (at + your option) any later version. + + The GNU Hurd 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, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ + +#include "netfs.h" +#include "fs_S.h" + +error_t +netfs_S_file_record_lock (struct protid *cred, + int cmd, + struct flock64 *flock) +{ + return EOPNOTSUPP; +}
[PATCH glibc] Add file record locking support
Hi, Attached is the patch adding support for file record locking in glibc, as implemented in Hurd by Neal Walfield and others. This patch should be applied after the corresponding hurd patch series in case glibc and hurd are not built simultaneously. (Maybe the conversion functions as written by Samuel should be used to verify struct sizes: http://lists.gnu.org/archive/html/bug-hurd/2014-08/msg00082.html) Thanks! sysdeps/mach/hurd/Changelog 2014-08-21 Svante Signell * fcntl.c: Add support for file-record-lock RPC fixing posix file locking using the flock64 version of struct flock. * bits/fcntl.h: Since MIG cannot mix 32 bit and 64 bit integers define unique numbers for F_GETLK64, F_SETLK64 and F_SETLKW64 to prepare for a flock64 implementation of file record locking in hurd. Index: glibc-2.19/sysdeps/mach/hurd/bits/fcntl.h === --- glibc-2.19.orig/sysdeps/mach/hurd/bits/fcntl.h +++ glibc-2.19/sysdeps/mach/hurd/bits/fcntl.h @@ -163,9 +163,18 @@ # define F_GETOWN 5 /* Get owner (receiver of SIGIO). */ # define F_SETOWN 6 /* Set owner (receiver of SIGIO). */ #endif +#ifdef __USE_FILE_OFFSET64 +# define F_GETLK F_GETLK64 +# define F_SETLK F_SETLK64 +# define F_SETLKW F_SETLKW64 +#else #define F_GETLK 7 /* Get record locking info. */ #define F_SETLK 8 /* Set record locking info (non-blocking). */ #define F_SETLKW 9 /* Set record locking info (blocking). */ +#endif +#define F_GETLK64 10 /* Get record locking info. */ +#define F_SETLK64 11 /* Set record locking info (non-blocking). */ +#define F_SETLKW64 12 /* Set record locking info (blocking). */ #ifdef __USE_XOPEN2K8 # define F_DUPFD_CLOEXEC 1030 /* Duplicate, set FD_CLOEXEC on new one. */ Index: glibc-2.19/sysdeps/mach/hurd/fcntl.c === --- glibc-2.19.orig/sysdeps/mach/hurd/fcntl.c +++ glibc-2.19/sysdeps/mach/hurd/fcntl.c @@ -20,7 +20,6 @@ #include #include #include -#include /* XXX for LOCK_* */ /* Perform file control operations on FD. */ int @@ -128,56 +127,87 @@ __libc_fcntl (int fd, int cmd, ...) case F_SETLK: case F_SETLKW: { - /* XXX - We need new RPCs to support POSIX.1 fcntl file locking!! - For the time being we support the whole-file case only, - with all kinds of WRONG WRONG WRONG semantics, - by using flock. This is definitely the Wrong Thing, - but it might be better than nothing (?). */ struct flock *fl = va_arg (ap, struct flock *); - va_end (ap); - switch (cmd) - { - case F_GETLK: - errno = ENOSYS; - return -1; - case F_SETLK: - cmd = LOCK_NB; - break; - default: - cmd = 0; + struct flock64 *fl64 = malloc (sizeof (struct flock64)); + + if (cmd == F_GETLK) + cmd = F_GETLK64; + if (cmd == F_SETLK) + cmd = F_SETLK64; + if (cmd == F_SETLKW) + cmd = F_SETLKW64; + +switch (fl->l_type) + { + case F_RDLCK: + case F_WRLCK: + case F_UNLCK: break; - } - switch (fl->l_type) - { - case F_RDLCK: cmd |= LOCK_SH | __LOCK_ATOMIC; break; - case F_WRLCK: cmd |= LOCK_EX | __LOCK_ATOMIC; break; - case F_UNLCK: cmd |= LOCK_UN; break; default: errno = EINVAL; return -1; + break; } - switch (fl->l_whence) - { - case SEEK_SET: - if (fl->l_start == 0 && fl->l_len == 0) /* Whole file request. */ - break; - /* It seems to be common for applications to lock the first - byte of the file when they are really doing whole-file locking. - So, since it's so wrong already, might as well do that too. */ - if (fl->l_start == 0 && fl->l_len == 1) - break; - /* FALLTHROUGH */ - case SEEK_CUR: - case SEEK_END: - errno = ENOTSUP; - return -1; +switch (fl->l_whence) + { + case SEEK_SET: + case SEEK_CUR: + case SEEK_END: + break; + default: +errno = EINVAL; +return -1; + break; + } + + fl64->l_type = fl->l_type; + fl64->l_whence = fl->l_whence; + fl64->l_start = fl->l_start; + fl64->l_len = fl->l_len; + fl64->l_pid = fl->l_pid; + err = HURD_FD_PORT_USE (d, __file_record_lock (port, cmd, fl64)); + fl->l_type = fl64->l_type; + fl->l_whence = fl64->l_whence; + fl->l_start = fl64->l_start; + fl->l_len = fl64->l_len; + fl->l_pid = fl64->l_pid; + free (fl64); + result = err ? __hurd_dfail (fd, err) : 0; + break; + } + +case F_GETLK64: +case F_SETLK64: +case F_SETLKW64: + { + struct flock64 *fl = va_arg (ap, struct flock64 *); + +switch (fl->l_type) + { + case F_RDLCK: + case F_WRLCK: + case F_UNLCK: + break; default: errno = EINVAL; return -1; + break; + } +switch (fl->l_whence) + { + case SEEK_SET: + case SEEK_CUR: + case SEEK_END: + break; + default: +errno = EINVAL; +
Cannot send mails to the list with attachments??
Hi, What's wrong with sending emails with attachments to debian-hurd@lists.debian.org? > Delivery to the following recipient failed permanently: > > debian-hurd@lists.debian.org > > Technical details of permanent failure: > Google tried to deliver your message, but it was rejected by the > server for the recipient domain lists.debian.org by bendel.debian.org. > [2001:41b8:202:deb:216:36ff:fe40:4002]. > > The error that the other server returned was: > 550 5.7.1 No attachments allowed -- To UNSUBSCRIBE, email to debian-hurd-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: https://lists.debian.org/1420721924.2983.137.ca...@g3620.my.own.domain
Re: Cannot send mails to the list with attachments??
Svante Signell, le Thu 08 Jan 2015 13:58:44 +0100, a écrit : > What's wrong with sending emails with attachments to > debian-hurd@lists.debian.org? I have no idea. Was it big? Was it a text file or a binary blob? Probably better at least Cc listmaster. Samuel -- To UNSUBSCRIBE, email to debian-hurd-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: https://lists.debian.org/20150108130052.gg4...@type.bordeaux.inria.fr
Reaend: [PATCH hurd/debian] Add libfshelp-tests programs and documentation to hurd-dev
Since this patch was not allowed to be sent as an attachement to debian-h...@listys.debian.org, I'm copying it directly into this email. Hi, Attached is the patch for debian/hurd-dev.install.in to include the four test programs locks, race, fork, checklock and documentation for some of them. This patch is part of the patches sent to bug-hurd (and debian-hurd) entitled: Add file record locking support. debian/hurd-dev-install.in: * Add libfshelp-tests/{locks,race,checklock,fork} to hurd-dev:bin * Add libfshelp-tests/{README,locks-tests} to hurd-dev:usr/share/doc/hurd-dev --- a/debian/hurd-dev.install.in2014-12-10 02:15:08.0 +0100 +++ b/debian/hurd-dev.install.in2014-12-12 11:56:31.0 +0100 @@ -5,6 +5,12 @@ ../local/soundcard.h usr/include/sys bin/fstests bin/timertest +bin/locks +../../libfshelp-tests/locks-tests bin/locks-tests +../../libfshelp-tests/README usr/share/doc/hurd-dev/README.locks +bin/race +bin/checklock +bin/fork include/* usr/include lib/@DEB_HOST_MULTIARCH@/*.a lib/@DEB_HOST_MULTIARCH@/*.so -- To UNSUBSCRIBE, email to debian-hurd-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: https://lists.debian.org/1420722706.2983.146.ca...@g3620.my.own.domain
Re: Reaend: [PATCH hurd/debian] Add libfshelp-tests programs and documentation to hurd-dev
Svante Signell, le Thu 08 Jan 2015 14:11:46 +0100, a écrit : > Attached is the patch for debian/hurd-dev.install.in to include the > four test programs locks, race, fork, checklock and documentation for > some of them. Mmm, why shipping the tests? I haven't seen any debian package doing that: we usually just run them at build time. Samuel -- To UNSUBSCRIBE, email to debian-hurd-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: https://lists.debian.org/20150108131733.gj4...@type.bordeaux.inria.fr
Re: Reaend: [PATCH hurd/debian] Add libfshelp-tests programs and documentation to hurd-dev
On Thu, 2015-01-08 at 14:17 +0100, Samuel Thibault wrote: > Svante Signell, le Thu 08 Jan 2015 14:11:46 +0100, a écrit : > > Attached is the patch for debian/hurd-dev.install.in to include the > > four test programs locks, race, fork, checklock and documentation for > > some of them. > > Mmm, why shipping the tests? I haven't seen any debian package doing > that: we usually just run them at build time. Well, in the hurd-dev package there are already two tests included: ./bin/fstests ./bin/timertest (and they are not run during build time) Never mind, just ignore this patch. -- To UNSUBSCRIBE, email to debian-hurd-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: https://lists.debian.org/1420723846.2983.150.ca...@g3620.my.own.domain
Re: Reaend: [PATCH hurd/debian] Add libfshelp-tests programs and documentation to hurd-dev
Svante Signell, le Thu 08 Jan 2015 14:30:46 +0100, a écrit : > On Thu, 2015-01-08 at 14:17 +0100, Samuel Thibault wrote: > > Svante Signell, le Thu 08 Jan 2015 14:11:46 +0100, a écrit : > > > Attached is the patch for debian/hurd-dev.install.in to include the > > > four test programs locks, race, fork, checklock and documentation for > > > some of them. > > > > Mmm, why shipping the tests? I haven't seen any debian package doing > > that: we usually just run them at build time. > > Well, in the hurd-dev package there are already two tests included: > ./bin/fstests > ./bin/timertest > (and they are not run during build time) Well, I'd say they should not be installed, but run at build time :) Samuel -- To UNSUBSCRIBE, email to debian-hurd-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: https://lists.debian.org/20150108133602.gk4...@type.bordeaux.inria.fr
Re: Resend: [PATCH hurd/debian] Add libfshelp-tests programs and documentation to hurd-dev
On Thu, 2015-01-08 at 14:36 +0100, Samuel Thibault wrote: > Svante Signell, le Thu 08 Jan 2015 14:30:46 +0100, a écrit : > > On Thu, 2015-01-08 at 14:17 +0100, Samuel Thibault wrote: > > > Svante Signell, le Thu 08 Jan 2015 14:11:46 +0100, a écrit : > > > > Attached is the patch for debian/hurd-dev.install.in to include the > > > > four test programs locks, race, fork, checklock and documentation for > > > > some of them. > > > > > > Mmm, why shipping the tests? I haven't seen any debian package doing > > > that: we usually just run them at build time. > > > > Well, in the hurd-dev package there are already two tests included: > > ./bin/fstests > > ./bin/timertest > > (and they are not run during build time) > > Well, I'd say they should not be installed, but run at build time :) Ok, when a testsuite has been created for the debian/hurd build, including the tests above, I'll add the new libfshelp-tests to it :) -- To UNSUBSCRIBE, email to debian-hurd-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: https://lists.debian.org/1420730436.2983.153.ca...@g3620.my.own.domain
Re: [PATCH glibc] Add file record locking support
On Thu, 2015-01-08 at 12:40:12 +0100, Svante Signell wrote: > Index: glibc-2.19/sysdeps/mach/hurd/fcntl.c > === > --- glibc-2.19.orig/sysdeps/mach/hurd/fcntl.c > +++ glibc-2.19/sysdeps/mach/hurd/fcntl.c > @@ -128,56 +127,87 @@ __libc_fcntl (int fd, int cmd, ...) > case F_SETLK: > case F_SETLKW: >{ […] > struct flock *fl = va_arg (ap, struct flock *); […] > + struct flock64 *fl64 = malloc (sizeof (struct flock64)); You are not checking if malloc failed, but in any case there's no need at all to malloc the struct, just use «struct flock64 fl64». > +switch (fl->l_whence) > + { > + case SEEK_SET: > + case SEEK_CUR: > + case SEEK_END: > + break; > + default: > +errno = EINVAL; > +return -1; > + break; > + } The indentation here and in previous places seems messed up, check for space vs tab and similar. Thanks, Guillem -- To UNSUBSCRIBE, email to debian-hurd-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: https://lists.debian.org/20150108155645.ga12...@gaara.hadrons.org
Re: [PATCH glibc] Add file record locking support
On Thu, 2015-01-08 at 16:56 +0100, Guillem Jover wrote: > On Thu, 2015-01-08 at 12:40:12 +0100, Svante Signell wrote: > > Index: glibc-2.19/sysdeps/mach/hurd/fcntl.c > > === > > --- glibc-2.19.orig/sysdeps/mach/hurd/fcntl.c > > +++ glibc-2.19/sysdeps/mach/hurd/fcntl.c > > @@ -128,56 +127,87 @@ __libc_fcntl (int fd, int cmd, ...) > > case F_SETLK: > > case F_SETLKW: > >{ > […] > > struct flock *fl = va_arg (ap, struct flock *); > […] > > + struct flock64 *fl64 = malloc (sizeof (struct flock64)); > > You are not checking if malloc failed, but in any case there's no need > at all to malloc the struct, just use «struct flock64 fl64». Yes you are right, no checks are made. I removed the malloc part. What about freeing fl64 later on? > > +switch (fl->l_whence) > > + { > > + case SEEK_SET: > > + case SEEK_CUR: > > + case SEEK_END: > > + break; > > + default: > > +errno = EINVAL; > > +return -1; > > + break; > > + } > > The indentation here and in previous places seems messed up, check for > space vs tab and similar. Fixed! (hopefully) Updated patch attached. sysdeps/mach/hurd/Changelog 2014-08-21 Svante Signell * fcntl.c: Add support for file-record-lock RPC fixing posix file locking using the flock64 version of struct flock. * bits/fcntl.h: Since MIG cannot mix 32 bit and 64 bit integers define unique numbers for F_GETLK64, F_SETLK64 and F_SETLKW64 to prepare for a flock64 implementation of file record locking in hurd. Index: glibc-2.19/sysdeps/mach/hurd/bits/fcntl.h === --- glibc-2.19.orig/sysdeps/mach/hurd/bits/fcntl.h +++ glibc-2.19/sysdeps/mach/hurd/bits/fcntl.h @@ -163,9 +163,18 @@ # define F_GETOWN 5 /* Get owner (receiver of SIGIO). */ # define F_SETOWN 6 /* Set owner (receiver of SIGIO). */ #endif +#ifdef __USE_FILE_OFFSET64 +# define F_GETLK F_GETLK64 +# define F_SETLK F_SETLK64 +# define F_SETLKW F_SETLKW64 +#else #define F_GETLK 7 /* Get record locking info. */ #define F_SETLK 8 /* Set record locking info (non-blocking). */ #define F_SETLKW 9 /* Set record locking info (blocking). */ +#endif +#define F_GETLK64 10 /* Get record locking info. */ +#define F_SETLK64 11 /* Set record locking info (non-blocking). */ +#define F_SETLKW64 12 /* Set record locking info (blocking). */ #ifdef __USE_XOPEN2K8 # define F_DUPFD_CLOEXEC 1030 /* Duplicate, set FD_CLOEXEC on new one. */ Index: glibc-2.19/sysdeps/mach/hurd/fcntl.c === --- glibc-2.19.orig/sysdeps/mach/hurd/fcntl.c +++ glibc-2.19/sysdeps/mach/hurd/fcntl.c @@ -20,7 +20,6 @@ #include #include #include -#include /* XXX for LOCK_* */ /* Perform file control operations on FD. */ int @@ -128,56 +127,87 @@ __libc_fcntl (int fd, int cmd, ...) case F_SETLK: case F_SETLKW: { - /* XXX - We need new RPCs to support POSIX.1 fcntl file locking!! - For the time being we support the whole-file case only, - with all kinds of WRONG WRONG WRONG semantics, - by using flock. This is definitely the Wrong Thing, - but it might be better than nothing (?). */ struct flock *fl = va_arg (ap, struct flock *); - va_end (ap); - switch (cmd) + struct flock64 fl64; + + if (cmd == F_GETLK) + cmd = F_GETLK64; + if (cmd == F_SETLK) + cmd = F_SETLK64; + if (cmd == F_SETLKW) + cmd = F_SETLKW64; + + switch (fl->l_type) { - case F_GETLK: - errno = ENOSYS; - return -1; - case F_SETLK: - cmd = LOCK_NB; + case F_RDLCK: + case F_WRLCK: + case F_UNLCK: break; default: - cmd = 0; + errno = EINVAL; + return -1; break; } - switch (fl->l_type) + switch (fl->l_whence) { - case F_RDLCK: cmd |= LOCK_SH | __LOCK_ATOMIC; break; - case F_WRLCK: cmd |= LOCK_EX | __LOCK_ATOMIC; break; - case F_UNLCK: cmd |= LOCK_UN; break; + case SEEK_SET: + case SEEK_CUR: + case SEEK_END: + break; default: errno = EINVAL; return -1; + break; + } + + fl64->l_type = fl->l_type; + fl64->l_whence = fl->l_whence; + fl64->l_start = fl->l_start; + fl64->l_len = fl->l_len; + fl64->l_pid = fl->l_pid; + err = HURD_FD_PORT_USE (d, __file_record_lock (port, cmd, fl64)); + fl->l_type = fl64->l_type; + fl->l_whence = fl64->l_whence; + fl->l_start = fl64->l_start; + fl->l_len = fl64->l_len; + fl->l_pid = fl64->l_pid; + free (fl64); + result = err ? __hurd_dfail (fd, err) : 0; + break; + } + +case F_GETLK64: +case F_SETLK64: +case F_SETLKW64: + { + struct flock64 *fl = va_arg (ap, struct flock64 *); + +switch (fl->l_type) + { + case F_RDLCK: + case F_WRLCK: + case F_UNLCK: + break; + default: + errno = EINVAL; + return -1; + break; } switch (fl-
Re: [PATCH glibc] Add file record locking support
On Thu, 2015-01-08 at 18:03:31 +0100, Svante Signell wrote: > On Thu, 2015-01-08 at 16:56 +0100, Guillem Jover wrote: > > On Thu, 2015-01-08 at 12:40:12 +0100, Svante Signell wrote: > > > Index: glibc-2.19/sysdeps/mach/hurd/fcntl.c > > > === > > > --- glibc-2.19.orig/sysdeps/mach/hurd/fcntl.c > > > +++ glibc-2.19/sysdeps/mach/hurd/fcntl.c > > > @@ -128,56 +127,87 @@ __libc_fcntl (int fd, int cmd, ...) > > > case F_SETLK: > > > case F_SETLKW: > > >{ > > […] > > > struct flock *fl = va_arg (ap, struct flock *); > > […] > > > + struct flock64 *fl64 = malloc (sizeof (struct flock64)); > > > > You are not checking if malloc failed, but in any case there's no need > > at all to malloc the struct, just use «struct flock64 fl64». > > Yes you are right, no checks are made. I removed the malloc part. What > about freeing fl64 later on? You cannot free() memory from the stack, no. It gets released automatically when it gets out of scope (but this is basic C). > Index: glibc-2.19/sysdeps/mach/hurd/fcntl.c > === > --- glibc-2.19.orig/sysdeps/mach/hurd/fcntl.c > +++ glibc-2.19/sysdeps/mach/hurd/fcntl.c > @@ -128,56 +127,87 @@ __libc_fcntl (int fd, int cmd, ...) > + struct flock64 fl64; > + fl64->l_type = fl->l_type; > + fl64->l_whence = fl->l_whence; > + fl64->l_start = fl->l_start; > + fl64->l_len = fl->l_len; > + fl64->l_pid = fl->l_pid; > + err = HURD_FD_PORT_USE (d, __file_record_lock (port, cmd, fl64)); > + fl->l_type = fl64->l_type; > + fl->l_whence = fl64->l_whence; > + fl->l_start = fl64->l_start; > + fl->l_len = fl64->l_len; > + fl->l_pid = fl64->l_pid; > + free (fl64); > + result = err ? __hurd_dfail (fd, err) : 0; > + break; > + } I'm assuming you didn't build this. It should be fl64., and __file_record_lock(..., &fl64), and the free() would also have given you an error there, please build-test it. > +case F_GETLK64: > +case F_SETLK64: > +case F_SETLKW64: > + { > + struct flock64 *fl = va_arg (ap, struct flock64 *); > + > +switch (fl->l_type) > + { Still space vs tab here. > + case F_RDLCK: > + case F_WRLCK: > + case F_UNLCK: > + break; > + default: > + errno = EINVAL; > + return -1; > + break; > } Thanks, Guillem -- To UNSUBSCRIBE, email to debian-hurd-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org Archive: https://lists.debian.org/20150108180630.ga16...@gaara.hadrons.org
Re: [PATCH glibc] Add file record locking support
On Thu, 2015-01-08 at 19:06 +0100, Guillem Jover wrote: > On Thu, 2015-01-08 at 18:03:31 +0100, Svante Signell wrote: > > On Thu, 2015-01-08 at 16:56 +0100, Guillem Jover wrote: > > > On Thu, 2015-01-08 at 12:40:12 +0100, Svante Signell wrote: > > Yes you are right, no checks are made. I removed the malloc part. What > > about freeing fl64 later on? > > You cannot free() memory from the stack, no. It gets released > automatically when it gets out of scope (but this is basic C). Of course. > > I'm assuming you didn't build this. It should be fl64., and > __file_record_lock(..., &fl64), and the free() would also have given > you an error there, please build-test it. You made me confused, so all changes were not made. I think the malloc version was better for symmetry reasons. Changed anyway. > > +case F_GETLK64: > > +case F_SETLK64: > > +case F_SETLKW64: > > + { > > + struct flock64 *fl = va_arg (ap, struct flock64 *); > > + > > +switch (fl->l_type) > > + { > > Still space vs tab here. Yes, the editor adds spaces up till 7 blanks, and eight spaces are replaced by a tab, and the adds spces until two tabs, etc. The other code does also contain these constructs. What to do, untabify the whole file? Updated patch, building in progress. sysdeps/mach/hurd/Changelog 2014-08-21 Svante Signell * fcntl.c: Add support for file-record-lock RPC fixing posix file locking using the flock64 version of struct flock. * bits/fcntl.h: Since MIG cannot mix 32 bit and 64 bit integers define unique numbers for F_GETLK64, F_SETLK64 and F_SETLKW64 to prepare for a flock64 implementation of file record locking in hurd. Index: glibc-2.19/sysdeps/mach/hurd/bits/fcntl.h === --- glibc-2.19.orig/sysdeps/mach/hurd/bits/fcntl.h +++ glibc-2.19/sysdeps/mach/hurd/bits/fcntl.h @@ -163,9 +163,18 @@ # define F_GETOWN 5 /* Get owner (receiver of SIGIO). */ # define F_SETOWN 6 /* Set owner (receiver of SIGIO). */ #endif +#ifdef __USE_FILE_OFFSET64 +# define F_GETLK F_GETLK64 +# define F_SETLK F_SETLK64 +# define F_SETLKW F_SETLKW64 +#else #define F_GETLK 7 /* Get record locking info. */ #define F_SETLK 8 /* Set record locking info (non-blocking). */ #define F_SETLKW 9 /* Set record locking info (blocking). */ +#endif +#define F_GETLK64 10 /* Get record locking info. */ +#define F_SETLK64 11 /* Set record locking info (non-blocking). */ +#define F_SETLKW64 12 /* Set record locking info (blocking). */ #ifdef __USE_XOPEN2K8 # define F_DUPFD_CLOEXEC 1030 /* Duplicate, set FD_CLOEXEC on new one. */ Index: glibc-2.19/sysdeps/mach/hurd/fcntl.c === --- glibc-2.19.orig/sysdeps/mach/hurd/fcntl.c +++ glibc-2.19/sysdeps/mach/hurd/fcntl.c @@ -20,7 +20,6 @@ #include #include #include -#include /* XXX for LOCK_* */ /* Perform file control operations on FD. */ int @@ -128,56 +127,86 @@ __libc_fcntl (int fd, int cmd, ...) case F_SETLK: case F_SETLKW: { - /* XXX - We need new RPCs to support POSIX.1 fcntl file locking!! - For the time being we support the whole-file case only, - with all kinds of WRONG WRONG WRONG semantics, - by using flock. This is definitely the Wrong Thing, - but it might be better than nothing (?). */ struct flock *fl = va_arg (ap, struct flock *); - va_end (ap); - switch (cmd) + struct flock64 fl64; + + if (cmd == F_GETLK) + cmd = F_GETLK64; + if (cmd == F_SETLK) + cmd = F_SETLK64; + if (cmd == F_SETLKW) + cmd = F_SETLKW64; + + switch (fl->l_type) { - case F_GETLK: - errno = ENOSYS; + case F_RDLCK: + case F_WRLCK: + case F_UNLCK: + break; + default: + errno = EINVAL; return -1; - case F_SETLK: - cmd = LOCK_NB; + break; + } + switch (fl->l_whence) + { + case SEEK_SET: + case SEEK_CUR: + case SEEK_END: break; default: - cmd = 0; + errno = EINVAL; + return -1; break; } + + fl64.l_type = fl->l_type; + fl64.l_whence = fl->l_whence; + fl64.l_start = fl->l_start; + fl64.l_len = fl->l_len; + fl64.l_pid = fl->l_pid; + err = HURD_FD_PORT_USE (d, __file_record_lock (port, cmd, &fl64)); + fl->l_type = fl64.l_type; + fl->l_whence = fl64.l_whence; + fl->l_start = fl64.l_start; + fl->l_len = fl64.l_len; + fl->l_pid = fl64.l_pid; + result = err ? __hurd_dfail (fd, err) : 0; + break; + } + +case F_GETLK64: +case F_SETLK64: +case F_SETLKW64: + { + struct flock64 *fl = va_arg (ap, struct flock64 *); + switch (fl->l_type) { - case F_RDLCK: cmd |= LOCK_SH | __LOCK_ATOMIC; break; - case F_WRLCK: cmd |= LOCK_EX | __LOCK_ATOMIC; break; - case F_UNLCK: cmd |= LOCK_UN; break; + case F_RDLCK: + case F_WRLCK: + case F_UNLCK: + break; default: errno = EINVAL; return -1; + break; } switch (fl->l_whence) { case SEEK_SET: