]> git.proxmox.com Git - mirror_lxc.git/commitdiff
Remove the usage of a lock file
authorDaniel Lezcano <daniel.lezcano@free.fr>
Thu, 12 Nov 2009 13:40:14 +0000 (14:40 +0100)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Thu, 12 Nov 2009 13:40:14 +0000 (14:40 +0100)
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 <dlezcano@fr.ibm.com>
src/lxc/create.c
src/lxc/destroy.c
src/lxc/lock.c [deleted file]
src/lxc/lock.h [deleted file]
src/lxc/lxc.h
src/lxc/start.c
src/lxc/start.h

index a78aaed170fddd0c13ed4f3455f8502ec157c671..881caefb41cc1ea8a02791372453c5ad6dcaf111 100644 (file)
@@ -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;
index 9c75ea03cb8d1b7a6f16a038c21ccdeb5a573f56..953e93b10fc98d8976c41964e8657a3d9957e137 100644 (file)
@@ -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/<name> 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 (file)
index 820668b..0000000
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * lxc: linux Container library
- *
- * (C) Copyright IBM Corp. 2007, 2008
- *
- * Authors:
- * Daniel Lezcano <dlezcano at fr.ibm.com>
- *
- * 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 <stdio.h>
-#undef _GNU_SOURCE
-#include <errno.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/file.h>
-#include <sys/param.h>
-
-#include "error.h"
-#include "config.h"
-
-#include <lxc/lxc.h>
-
-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 (file)
index b6f6ac2..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * lxc: linux Container library
- *
- * (C) Copyright IBM Corp. 2007, 2008
- *
- * Authors:
- * Daniel Lezcano <dlezcano at fr.ibm.com>
- *
- * 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
index 327a90becfb1372a2e4f86e76a488a0826a3462b..4693f43f0c37a519f87d12d9263e019ab16a1c9c 100644 (file)
@@ -37,7 +37,6 @@ extern "C" {
 #include <lxc/list.h>
 #include <lxc/log.h>
 #include <lxc/conf.h>
-#include <lxc/lock.h>
 #include <lxc/namespace.h>
 #include <lxc/utils.h>
 #include <lxc/error.h>
index 5759024082e6ee903d517a4151b29ab38eb34ca0..dd81fccbdb1923a160594f6e75201d5a6f7c0b49 100644 (file)
@@ -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);
        }
 
index 805a3a47c616f0a3755a69ac70940ae5b0b4e6c0..8b46b66b40004c672fa02ead4e0a32482a070a84 100644 (file)
@@ -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;