[Gluster-devel] Proper error path handling when libgfapi routines fail

Anand Avati anand.avati at gmail.com
Wed Jul 18 06:44:23 UTC 2012


I plan to enhance glfs_fini() to be the common destruction routine for
initialized and half-initialized objects. So call glfs_fini() for all
failures for now and assume libgfapi will do the cleanup.

Avati

On Tue, Jul 17, 2012 at 11:06 PM, Bharata B Rao <bharata.rao at gmail.com>wrote:

> Hi Avati,
>
> In QEMU, this is how I am planning to use libgfapi to set the GlusterFS
> backend.
>
> struct glfs *glfs;
> int ret = 0;
>
> glfs = glfs_new(volname);
> if (!glfs) {
>     ret = -errno;
>     goto out_glfs_new_failed;
> }
>
> ret = glfs_set_volfile_server(glfs, "socket", server, port);
> if (ret < 0) {
>     ret = -errno;
>     goto out_set_volfile_failed;
> }
>
> /* optional */
> ret = glfs_set_logging(glfs, logfile, loglevel);
> if (ret < 0) {
>     ret = -errno;
>     goto out_set_logging_failed;
> }
>
> ret = glfs_init(glfs);
> if (ret < 0) {
>     ret = -errno;
>     goto out_glfs_init_failed;
> }
> return ret;
>
> out_glfs_init_failed:
>     glfs_unset_logging(glfs, ...);
> out_set_logging_failed:
>     glfs_unset_volfile_server(glfs, ...);
> out_set_volfile_failed:
>     glfs_free(glfs);
> out_glfs_new_failed:
>     return ret;
>
> I see only glfs_fini() in libgfapi currently. I see that all of the
> APIs I am using above at least allocate memory which needs to be freed
> up at the end or during failure. Are such cleanup routines already
> present in libgfapi that could use ? If not, can you please provide
> the clean up routines for the above mentioned 4 APIs that QEMU would
> be using ?
>
> Regards,
> Bharata.
> --
> http://bharata.sulekha.com/blog/posts.htm,
> http://raobharata.wordpress.com/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://supercolony.gluster.org/pipermail/gluster-devel/attachments/20120717/39e4f818/attachment-0003.html>


More information about the Gluster-devel mailing list