lxc_destroy.c revision 5a21336025eec5b4228994d0efece129257411bd
/*
*
* Copyright © 2013 Serge Hallyn <serge.hallyn@ubuntu.com>.
* Copyright © 2013 Canonical Ltd.
*
* it under the terms of the GNU General Public License version 2, as
* published by the Free Software Foundation.
*
* 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#define _GNU_SOURCE
#include "config.h"
#include <libgen.h>
#include <stdio.h>
#include <unistd.h>
#include <lxc/lxccontainer.h>
#include "arguments.h"
#include "log.h"
#include "lxc.h"
#include "utils.h"
static bool quiet;
static const struct option my_longopts[] = {
};
static struct lxc_arguments my_args = {
.progname = "lxc-destroy",
.help = "\
--name=NAME [-f] [-P lxcpath]\n\
\n\
lxc-destroy destroys a container with the identifier NAME\n\
\n\
Options :\n\
-n, --name=NAME NAME of the container\n\
-s, --snapshots destroy including all snapshots\n\
-f, --force wait for the container to shut down\n",
.options = my_longopts,
};
static bool do_destroy(struct lxc_container *c);
static bool do_destroy_with_snapshots(struct lxc_container *c);
{
struct lxc_container *c;
bool bret;
quiet = true;
if (!c) {
if (!quiet)
}
if (!c->may_control(c)) {
if (!quiet)
}
if (!c->is_defined(c)) {
if (!quiet)
}
} else {
bret = do_destroy(c);
}
if (bret)
}
{
switch (c) {
}
return 0;
}
static bool do_destroy(struct lxc_container *c)
{
bool bret = true;
char path[MAXPATHLEN];
/* First check whether the container has dependent clones or snapshots. */
return false;
if (file_exists(path)) {
if (!quiet)
return false;
}
return false;
if (dir_exists(path)) {
if (!quiet)
return false;
}
if (c->is_running(c)) {
return false;
}
/* If the container was ephemeral it will be removed on shutdown. */
c->stop(c);
}
/* If the container was ephemeral we have already removed it when we
* stopped it. */
if (!bret) {
if (!quiet)
return false;
}
return true;
}
static bool do_destroy_with_snapshots(struct lxc_container *c)
{
struct lxc_container *c1;
bool bret = false;
char path[MAXPATHLEN];
int fd;
int ret;
int counter = 0;
/* Destroy clones. */
return false;
if (fd >= 0) {
if (ret < 0) {
return false;
}
/* Make sure that the string is \0 terminated. */
if (!buf) {
SYSERROR("failed to allocate memory");
return false;
}
if (ret < 0) {
return false;
}
break;
if (!c1) {
counter++;
continue;
}
/* We do not destroy recursively. If a clone of a clone
* has clones or snapshots the user should remove it
* explicitly. */
if (!do_destroy(c1)) {
return false;
}
counter++;
}
}
/* Destroy snapshots located in the containers snap/ folder. */
return false;
if (dir_exists(path))
bret = c->destroy_with_snapshots(c);
else
bret = do_destroy(c);
return bret;
}