[lxc-devel] [PATCH] Track snapshot dependencies

Serge Hallyn serge.hallyn at ubuntu.com
Wed Aug 21 15:47:20 UTC 2013


Quoting Dwight Engen (dwight.engen at oracle.com):
> 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?

I had thought about it, but note that the dependency tracking is
best-effort.  I don't want an lxc-clone to fail bc we couldn't
mark the dependency.  Maybe I'm wrong on that, and I should.
What do you think?

> [...]
> > +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