[lxc-devel] [PATCH] Track snapshot dependencies

Dwight Engen dwight.engen at oracle.com
Wed Aug 21 15:28:42 UTC 2013


On Tue, 20 Aug 2013 14:15:26 -0500
Serge Hallyn <serge.hallyn at ubuntu.com> wrote:

[...]
> +static bool mod_rdep(struct lxc_container *c, bool inc)
> +{
> +	char path[MAXPATHLEN];
> +	int ret, v = 0;
> +	FILE *f;
> +	bool bret = false;
> +
> +	if (container_disk_lock(c))
> +		return false;
> +	ret = snprintf(path, MAXPATHLEN, "%s/%s/lxc_snapshots",
> c->config_path,
> +			c->name);
> +	if (ret < 0 || ret > MAXPATHLEN)
> +		goto out;
> +	f = fopen(path, "r");
> +	if (f) {
> +		ret = fscanf(f, "%d", &v);
> +		fclose(f);
> +		if (ret != 1) {
> +			ERROR("Corrupted file %s", path);
> +			goto out;
> +		}
> +	}
> +	v += inc ? 1 : -1;
> +	f = fopen(path, "w");
> +	if (!f)
> +		goto out;
> +	fprintf(f, "%d\n", v);
> +	fclose(f);

Should we check the return value of fclose()? ie. it could fail ENOSPC?

[...]
> +static bool add_rdepends(struct lxc_container *c, struct
> lxc_container *c0) +{
> +	int ret;
> +	char path[MAXPATHLEN];
> +	FILE *f;
> +
> +	ret = snprintf(path, MAXPATHLEN, "%s/%s/lxc_rdepends",
> c->config_path,
> +		c->name);
> +	if (ret < 0 || ret >= MAXPATHLEN)
> +		return false;
> +	f = fopen(path, "a");
> +	if (!f)
> +		return false;
> +	fprintf(f, "%s\n%s\n", c0->config_path, c0->name);
> +	fclose(f);

and here, otherwise

Acked-by: Dwight Engen <dwight.engen at oracle.com>




More information about the lxc-devel mailing list