From 3c379ff78e0b119d08effc013a081bb311b1c821 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Thu, 16 Aug 2012 10:59:54 +0200 Subject: [PATCH] xbps-repo: remove repo index file locking, it's unreliable under NFS. --- NEWS | 3 -- bin/xbps-repo/Makefile | 2 +- bin/xbps-repo/index-files.c | 31 +++-------- bin/xbps-repo/index-lock.c | 103 ------------------------------------ bin/xbps-repo/index.c | 23 ++------ 5 files changed, 10 insertions(+), 152 deletions(-) delete mode 100644 bin/xbps-repo/index-lock.c diff --git a/NEWS b/NEWS index f882b364..44821834 100644 --- a/NEWS +++ b/NEWS @@ -26,9 +26,6 @@ xbps-0.17 (???): $ xbps-repo index-clean /path/to/repo - File locking has been implemented for these targets to only allow a client - to update the index files. - xbps-0.16.5 (2012-07-14): * xbps.conf: remove obsolete remote repositories. diff --git a/bin/xbps-repo/Makefile b/bin/xbps-repo/Makefile index 6c2106d5..a99fff5c 100644 --- a/bin/xbps-repo/Makefile +++ b/bin/xbps-repo/Makefile @@ -3,7 +3,7 @@ TOPDIR = ../.. BIN = xbps-repo OBJS = main.o index.o show.o find-files.o list.o -OBJS += index-files.o index-lock.o clean.o common.o +OBJS += index-files.o clean.o common.o OBJS += remove-obsoletes.o OBJS += ../xbps-bin/fetch_cb.o ../xbps-bin/util.o OBJS += ../xbps-bin/state_cb.o ../xbps-bin/list.o diff --git a/bin/xbps-repo/index-files.c b/bin/xbps-repo/index-files.c index 8b98fa1d..0ba75c46 100644 --- a/bin/xbps-repo/index-files.c +++ b/bin/xbps-repo/index-files.c @@ -39,13 +39,13 @@ repo_index_files_clean(struct xbps_handle *xhp, const char *repodir) { prop_object_t obj; prop_array_t idx, idxfiles, obsoletes; - char *plist, *plistf, *plistf_lock, *pkgver, *str; + char *plist, *plistf, *pkgver, *str; const char *p, *arch, *ipkgver, *iarch; size_t x, i; - int rv = 0, fdlock; + int rv = 0; bool flush = false; - plist = plistf = plistf_lock = pkgver = str = NULL; + plist = plistf = pkgver = str = NULL; idx = idxfiles = obsoletes = NULL; /* Internalize index-files.plist if found */ @@ -55,20 +55,12 @@ repo_index_files_clean(struct xbps_handle *xhp, const char *repodir) free(plistf); return 0; } - /* Acquire exclusive file lock */ - if ((fdlock = acquire_repo_lock(plistf, &plistf_lock)) == -1) { - free(plistf); - prop_object_release(idxfiles); - return -1; - } - /* Internalize index.plist */ if ((plist = xbps_pkg_index_plist(xhp, repodir)) == NULL) { rv = EINVAL; goto out; } if ((idx = prop_array_internalize_from_zfile(plist)) == NULL) { - release_repo_lock(&plistf_lock, fdlock); rv = EINVAL; goto out; } @@ -131,8 +123,6 @@ repo_index_files_clean(struct xbps_handle *xhp, const char *repodir) prop_array_count(idxfiles)); out: - release_repo_lock(&plistf_lock, fdlock); - if (obsoletes) prop_object_release(obsoletes); if (idx) @@ -155,13 +145,13 @@ repo_index_files_add(struct xbps_handle *xhp, int argc, char **argv) prop_dictionary_t pkgprops, pkg_filesd, pkgd; prop_array_t files, pkg_cffiles, pkg_files, pkg_links; const char *binpkg, *pkgver, *arch; - char *plist, *repodir, *p, *plist_lock; + char *plist, *repodir, *p; size_t x; - int i, fdlock = -1, rv = 0; + int i, rv = 0; bool found, flush; found = flush = false; - plist = plist_lock = repodir = p = NULL; + plist = repodir = p = NULL; obj = fileobj = NULL; pkgprops = pkg_filesd = pkgd = NULL; files = NULL; @@ -175,13 +165,6 @@ repo_index_files_add(struct xbps_handle *xhp, int argc, char **argv) rv = ENOMEM; goto out; } - /* Acquire exclusive file lock or wait for it. - */ - if ((fdlock = acquire_repo_lock(plist, &plist_lock)) == -1) { - free(p); - free(plist); - return -1; - } /* * Internalize index-files.plist if found and process argv. */ @@ -365,8 +348,6 @@ repo_index_files_add(struct xbps_handle *xhp, int argc, char **argv) prop_array_count(idxfiles)); out: - release_repo_lock(&plist_lock, fdlock); - if (p) free(p); if (plist) diff --git a/bin/xbps-repo/index-lock.c b/bin/xbps-repo/index-lock.c deleted file mode 100644 index 85bfbe5c..00000000 --- a/bin/xbps-repo/index-lock.c +++ /dev/null @@ -1,103 +0,0 @@ -/*- - * Copyright (c) 2012 Juan Romero Pardines. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include "defs.h" - -int -acquire_repo_lock(const char *plist, char **plist_lock) -{ - int try = 0, fd = -1; - - *plist_lock = xbps_xasprintf("%s.lock", plist); - assert(*plist_lock); - - fd = open(*plist_lock, O_RDWR); - if (fd == -1) { - if (errno == ENOENT) { - fd = creat(*plist_lock, 0640); - if (fd == -1) { - fprintf(stderr, "Failed to create " - "repository file lock: %s\n", - strerror(errno)); - return -1; - } - } else { - fprintf(stderr, "Failed to open repository " - "file lock: %s\n", strerror(errno)); - return -1; - } - } - /* - * Acquire the the exclusive file lock or wait until - * it's available. - */ -#define WAIT_SECONDS 30 - while (lockf(fd, F_TLOCK, 0) < 0) { - if (errno == EAGAIN || errno == EACCES) { - if (++try < WAIT_SECONDS) { - fprintf(stderr,"Repository index file " - "is busy! retrying in 1 sec...\n"); - sleep(1); - continue; - } - } - fprintf(stderr, "Failed to acquire repository " - "file lock in %d seconds!\n", WAIT_SECONDS); - close(fd); - return -1; - } - return fd; -} - -void -release_repo_lock(char **plist_lock, int fd) -{ - assert(*plist_lock); - - if (fd == -1) - return; - if (lockf(fd, F_ULOCK, 0) == -1) { - fprintf(stderr, "failed to unlock file lock: %s\n", - strerror(errno)); - close(fd); - exit(EXIT_FAILURE); - } - close(fd); - unlink(*plist_lock); - free(*plist_lock); -} diff --git a/bin/xbps-repo/index.c b/bin/xbps-repo/index.c index 8bb47cb6..4ab64c97 100644 --- a/bin/xbps-repo/index.c +++ b/bin/xbps-repo/index.c @@ -46,29 +46,22 @@ repo_index_clean(struct xbps_handle *xhp, const char *repodir) prop_array_t array; prop_dictionary_t pkgd; const char *filen, *pkgver, *arch; - char *plist, *plist_lock; + char *plist; size_t i, idx = 0; - int fdlock, rv = 0; + int rv = 0; bool flush = false; if ((plist = xbps_pkg_index_plist(xhp, repodir)) == NULL) return -1; - if ((fdlock = acquire_repo_lock(plist, &plist_lock)) == -1) { - free(plist); - return -1; - } - array = prop_array_internalize_from_zfile(plist); if (array == NULL) { if (errno != ENOENT) { xbps_error_printf("xbps-repo: cannot read `%s': %s\n", plist, strerror(errno)); free(plist); - release_repo_lock(&plist_lock, fdlock); return -1; } else { - release_repo_lock(&plist_lock, fdlock); free(plist); return 0; } @@ -104,7 +97,6 @@ again: out: free(plist); prop_object_release(array); - release_repo_lock(&plist_lock, fdlock); return rv; } @@ -123,8 +115,7 @@ repo_index_add(struct xbps_handle *xhp, int argc, char **argv) const char *arch, *oldarch; char *sha256, *filen, *repodir, *buf, *buf2; char *tmpfilen = NULL, *tmprepodir = NULL, *plist = NULL; - char *plist_lock = NULL; - int i, ret = 0, rv = 0, fdlock = -1; + int i, ret = 0, rv = 0; bool flush = false; if ((tmprepodir = strdup(argv[1])) == NULL) { @@ -137,12 +128,6 @@ repo_index_add(struct xbps_handle *xhp, int argc, char **argv) if ((plist = xbps_pkg_index_plist(xhp, repodir)) == NULL) return -1; - /* Acquire exclusive file lock */ - if ((fdlock = acquire_repo_lock(plist, &plist_lock)) == -1) { - rv = fdlock; - goto out; - } - if ((idx = prop_array_internalize_from_zfile(plist)) == NULL) { if (errno != ENOENT) { xbps_error_printf("xbps-repo: cannot read `%s': %s\n", @@ -329,8 +314,6 @@ repo_index_add(struct xbps_handle *xhp, int argc, char **argv) printf("index: %u packages registered.\n", prop_array_count(idx)); out: - release_repo_lock(&plist_lock, fdlock); - if (tmprepodir) free(tmprepodir); if (plist)