From patchwork Tue Jul 23 08:30:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: MORITA Kazutaka X-Patchwork-Id: 260981 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 441892C00AB for ; Tue, 23 Jul 2013 18:33:44 +1000 (EST) Received: from localhost ([::1]:53771 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V1Y2P-0008Lr-Us for incoming@patchwork.ozlabs.org; Tue, 23 Jul 2013 04:33:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53886) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V1Y0H-00054T-HY for qemu-devel@nongnu.org; Tue, 23 Jul 2013 04:31:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V1Y0G-0001hr-9r for qemu-devel@nongnu.org; Tue, 23 Jul 2013 04:31:29 -0400 Received: from sh.osrg.net ([192.16.179.4]:37890) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V1Y0F-0001hT-MW for qemu-devel@nongnu.org; Tue, 23 Jul 2013 04:31:28 -0400 Received: from fs.osrg.net (localns.osrg.net [10.0.0.11]) by sh.osrg.net (8.14.4/8.14.4/OSRG-NET) with ESMTP id r6N8V8PV010583; Tue, 23 Jul 2013 17:31:08 +0900 Received: from localhost (unknown [10.32.32.72]) by fs.osrg.net (Postfix) with ESMTP id 60E05F94E; Tue, 23 Jul 2013 17:31:07 +0900 (JST) From: MORITA Kazutaka To: Kevin Wolf , Stefan Hajnoczi , qemu-devel@nongnu.org Date: Tue, 23 Jul 2013 17:30:17 +0900 Message-Id: <1374568221-23147-8-git-send-email-morita.kazutaka@lab.ntt.co.jp> X-Mailer: git-send-email 1.8.1.3.566.gaa39828 In-Reply-To: <1374568221-23147-1-git-send-email-morita.kazutaka@lab.ntt.co.jp> References: <1374568221-23147-1-git-send-email-morita.kazutaka@lab.ntt.co.jp> X-Dispatcher: imput version 20100215(IM150) Lines: 76 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.3.9 (sh.osrg.net [192.16.179.4]); Tue, 23 Jul 2013 17:31:08 +0900 (JST) X-Virus-Scanned: clamav-milter 0.97.8 at sh X-Virus-Status: Clean X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 192.16.179.4 Cc: sheepdog@lists.wpkg.org Subject: [Qemu-devel] [PATCH 07/11] sheepdog: reload inode outside of resend_aioreq X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This prepares for using resend_aioreq() after reconnecting to the sheepdog server. Signed-off-by: MORITA Kazutaka --- block/sheepdog.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index 018eab2..1173605 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -222,6 +222,11 @@ static inline uint64_t data_oid_to_idx(uint64_t oid) return oid & (MAX_DATA_OBJS - 1); } +static inline uint32_t oid_to_vid(uint64_t oid) +{ + return (oid & ~VDI_BIT) >> VDI_SPACE_SHIFT; +} + static inline uint64_t vid_to_vdi_oid(uint32_t vid) { return VDI_BIT | ((uint64_t)vid << VDI_SPACE_SHIFT); @@ -663,7 +668,7 @@ static int coroutine_fn add_aio_request(BDRVSheepdogState *s, AIOReq *aio_req, struct iovec *iov, int niov, bool create, enum AIOCBState aiocb_type); static int coroutine_fn resend_aioreq(BDRVSheepdogState *s, AIOReq *aio_req); - +static int reload_inode(BDRVSheepdogState *s, uint32_t snapid, const char *tag); static AIOReq *find_pending_req(BDRVSheepdogState *s, uint64_t oid) { @@ -811,6 +816,19 @@ static void coroutine_fn aio_read_response(void *opaque) case SD_RES_SUCCESS: break; case SD_RES_READONLY: + if (s->inode.vdi_id == oid_to_vid(aio_req->oid)) { + ret = reload_inode(s, 0, ""); + if (ret < 0) { + goto out; + } + } + + if (is_data_obj(aio_req->oid)) { + aio_req->oid = vid_to_data_oid(s->inode.vdi_id, + data_oid_to_idx(aio_req->oid)); + } else { + aio_req->oid = vid_to_vdi_oid(s->inode.vdi_id); + } ret = resend_aioreq(s, aio_req); if (ret == SD_RES_SUCCESS) { goto out; @@ -1258,19 +1276,6 @@ static int coroutine_fn resend_aioreq(BDRVSheepdogState *s, AIOReq *aio_req) { SheepdogAIOCB *acb = aio_req->aiocb; bool create = false; - int ret; - - ret = reload_inode(s, 0, ""); - if (ret < 0) { - return ret; - } - - if (is_data_obj(aio_req->oid)) { - aio_req->oid = vid_to_data_oid(s->inode.vdi_id, - data_oid_to_idx(aio_req->oid)); - } else { - aio_req->oid = vid_to_vdi_oid(s->inode.vdi_id); - } /* check whether this request becomes a CoW one */ if (acb->aiocb_type == AIOCB_WRITE_UDATA && is_data_obj(aio_req->oid)) {