From: Daniel Lezcano Date: Thu, 12 Nov 2009 13:40:14 +0000 (+0100) Subject: Remove the usage of a lock file X-Git-Tag: lxc_0_6_4~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=884866b3c305f1edd74c9ea7f082d009a86f3fd5;p=thirdparty%2Flxc.git Remove the usage of a lock file The lock is no longer needed as the mutual exclusion and 'is running' check is done via the af_unix command socket. Signed-off-by: Daniel Lezcano --- diff --git a/src/lxc/create.c b/src/lxc/create.c index a78aaed17..881caefb4 100644 --- a/src/lxc/create.c +++ b/src/lxc/create.c @@ -120,7 +120,7 @@ static int copy_config_file(const char *name, const char *file) int lxc_create(const char *name, const char *confile) { - int lock, err = -1; + int err = -1; if (create_lxc_directory(name)) return err; @@ -128,26 +128,21 @@ int lxc_create(const char *name, const char *confile) if (!confile) return 0; - lock = lxc_get_lock(name); - if (lock < 0) - goto err; - if (copy_config_file(name, confile)) { ERROR("failed to copy the configuration file"); - goto err_state; + goto err; } err = 0; out: - lxc_put_lock(lock); return err; -err_state: +err: lxc_unconfigure(name); if (lxc_rmstate(name)) ERROR("failed to remove state file for %s", name); -err: + if (remove_lxc_directory(name)) ERROR("failed to cleanup lxc directory for %s", name); goto out; diff --git a/src/lxc/destroy.c b/src/lxc/destroy.c index 9c75ea03c..953e93b10 100644 --- a/src/lxc/destroy.c +++ b/src/lxc/destroy.c @@ -71,19 +71,15 @@ static int remove_config_file(const char *name) int lxc_destroy(const char *name) { - int lock, ret = -1; + int ret = -1; char path[MAXPATHLEN]; - lock = lxc_get_lock(name); - if (lock < 0) - return ret; - if (remove_config_file(name)) WARN("failed to remove the configuration file"); if (lxc_rmstate(name)) { ERROR("failed to remove state file for %s", name); - goto out_lock; + return -1; } #warning keep access to LXCPATH/ to destroy old created container @@ -95,17 +91,13 @@ int lxc_destroy(const char *name) if (lxc_unconfigure(name)) { ERROR("failed to cleanup %s", name); - goto out_lock; + return -1; } if (remove_lxc_directory(name)) { SYSERROR("failed to remove '%s'", name); - goto out_lock; + return -1; } - ret = 0; - -out_lock: - lxc_put_lock(lock); - return ret; + return 0; } diff --git a/src/lxc/lock.c b/src/lxc/lock.c deleted file mode 100644 index 820668b0b..000000000 --- a/src/lxc/lock.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - * lxc: linux Container library - * - * (C) Copyright IBM Corp. 2007, 2008 - * - * Authors: - * Daniel Lezcano - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#define _GNU_SOURCE -#include -#undef _GNU_SOURCE -#include -#include -#include -#include -#include - -#include "error.h" -#include "config.h" - -#include - -lxc_log_define(lxc_lock, lxc); - -static int __lxc_get_lock(const char *name) -{ - char lock[MAXPATHLEN]; - int fd, ret; - - snprintf(lock, MAXPATHLEN, LXCPATH "/%s", name); - - /* need to check access because of cap_dac_override */ - if (access(lock, R_OK |W_OK | X_OK)) - return -errno; - - fd = open(lock, O_RDONLY|O_DIRECTORY, S_IRUSR|S_IWUSR); - if (fd < 0) - return -errno; - - fcntl(fd, F_SETFD, FD_CLOEXEC); - - if (flock(fd, LOCK_EX|LOCK_NB)) { - ret = -errno; - close(fd); - goto out; - } - - ret = fd; -out: - return ret; -} - -int lxc_get_lock(const char *name) -{ - int ret; - - ret = __lxc_get_lock(name); - if (ret < 0) - goto out_err; - - return ret; -out_err: - switch (-ret) { - case EWOULDBLOCK: - ERROR("container '%s' is busy", name); - break; - case ENOENT: - ERROR("container '%s' is not found", name); - break; - case EACCES: - ERROR("not enough privilege to use container '%s'", name); - break; - default: - ERROR("container '%s' failed to lock : %s", - name, strerror(-ret)); - } - return -1; -} - -int lxc_check_lock(const char *name) -{ - int ret; - - ret = __lxc_get_lock(name); - if (ret >= 0) { - ERROR("container '%s' is not active", name); - lxc_put_lock(ret); - return -1; - } - if (ret != -EWOULDBLOCK) { - ERROR("container '%s' : %s", name, strerror(-ret)); - return -1; - } - return 0; -} - -void lxc_put_lock(int lock) -{ - flock(lock, LOCK_UN); - close(lock); -} diff --git a/src/lxc/lock.h b/src/lxc/lock.h deleted file mode 100644 index b6f6ac26c..000000000 --- a/src/lxc/lock.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * lxc: linux Container library - * - * (C) Copyright IBM Corp. 2007, 2008 - * - * Authors: - * Daniel Lezcano - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -#ifndef _lock_h -#define _lock_h - -extern int lxc_get_lock(const char *name); -extern int lxc_check_lock(const char *name); -extern void lxc_put_lock(int lock); - -#endif diff --git a/src/lxc/lxc.h b/src/lxc/lxc.h index 327a90bec..4693f43f0 100644 --- a/src/lxc/lxc.h +++ b/src/lxc/lxc.h @@ -37,7 +37,6 @@ extern "C" { #include #include #include -#include #include #include #include diff --git a/src/lxc/start.c b/src/lxc/start.c index 575902408..dd81fccbd 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -246,14 +246,10 @@ struct lxc_handler *lxc_init(const char *name) memset(handler, 0, sizeof(*handler)); - handler->lock = lxc_get_lock(name); - if (handler->lock < 0) - goto out_free; - /* Begin the set the state to STARTING*/ if (set_state(name, handler, STARTING)) { ERROR("failed to set state '%s'", lxc_state2str(STARTING)); - goto out_put_lock; + goto out_free; } if (lxc_conf_init(&handler->conf)) { @@ -302,8 +298,6 @@ out_delete_tty: lxc_delete_tty(&handler->conf.tty_info); out_aborting: set_state(name, handler, ABORTING); -out_put_lock: - lxc_put_lock(handler->lock); out_free: free(handler); handler = NULL; @@ -322,7 +316,6 @@ void lxc_fini(const char *name, struct lxc_handler *handler) if (handler) { remove_init_pid(name, handler->pid); lxc_delete_tty(&handler->conf.tty_info); - lxc_put_lock(handler->lock); free(handler); } diff --git a/src/lxc/start.h b/src/lxc/start.h index 805a3a47c..8b46b66b4 100644 --- a/src/lxc/start.h +++ b/src/lxc/start.h @@ -27,7 +27,6 @@ struct lxc_handler { lxc_state_t state; int sigfd; - int lock; char nsgroup[MAXPATHLEN]; sigset_t oldmask; struct lxc_conf conf;