From: Ian Jackson Subject: Re: [PATCH v2 07/10] libxl: add Qdisk backend launch helper Date: Fri, 15 Nov 2013 17:34:58 +0000 Message-ID: <21126.23362.330554.215108@mariner.uk.xensource.com> References: <1384171831-21275-1-git-send-email-roger.pau@citrix.com> <1384171831-21275-8-git-send-email-roger.pau@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1VhNIR-0001QO-SW for xen-devel@lists.xenproject.org; Fri, 15 Nov 2013 17:35:08 +0000 In-Reply-To: <1384171831-21275-8-git-send-email-roger.pau@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Roger Pau Monne Cc: Anthony PERARD , xen-devel@lists.xenproject.org, Ian Campbell , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org Roger Pau Monne writes ("[PATCH v2 07/10] libxl: add Qdisk backend launch helper"): > Current Qemu launch functions in libxl require the usage of data > structures only avaialbe on domain creation. All this information is > not need in order to launch a Qemu instance to serve Qdisk backends, > so introduce a new simplified helper that can be used to launch > Qemu/Qdisk, that will be used to launch Qdisk in driver domains. I think the principle here is good, and the implementation is pretty good. Looking for code duplication: +void libxl__spawn_qdisk_backend(libxl__egc *egc, libxl__spawn_qdisk_state *sqs) ... > + libxl_create_logfile(CTX, GCSPRINTF("qdisk-%u", domid), &logfile); > + logfile_w = open(logfile, O_WRONLY|O_CREAT|O_APPEND, 0644); > + if (logfile_w < 0) { > + free(logfile); > + rc = logfile_w; > + goto error; > + } > + free(logfile); > + null = open("/dev/null", O_RDONLY); This is very like similar code in libxl__spawn_local_dm and could perhaps profitably be factored out into a function. > +static void qdisk_confirm(libxl__egc *egc, libxl__spawn_state *spawn, > + const char *xsdata) > +{ > + STATE_AO_GC(spawn->ao); > + > + if (!xsdata) > + return; > + > + if (strcmp(xsdata, "running")) > + return; > + > + libxl__spawn_initiate_detach(gc, spawn); > +} This is practically identical to device_model_confirm. Indeed, if you delete the unneeded line in device_model_confirm for getting the (unused) dmss, I think it's entirely identical. > +static void qdisk_startup_failed(libxl__egc *egc, > + libxl__spawn_state *spawn) > +{ > + libxl__spawn_qdisk_state *sqs = CONTAINER_OF(spawn, *sqs, spawn); > + sqs->callback(egc, sqs, ERROR_FAIL); > +} These are similar to the callbacks used by libxl__spawn_local_dm. If you used a libxl__dm_spawn_state (even if mostly full of null pointers) for the sqs, instead of its own type, you could abolish these separate callbacks and rely on device_model_spawn_outcome to DTRT I think. What do you think ? Thanks, Ian.