Blame 0005-hw-9pfs-Reset-server-state-during-TVERSION.patch

Justin M. Forbes 45e84a
From c554919f74e5a79f15360c4c2f417003477634cf Mon Sep 17 00:00:00 2001
Justin M. Forbes 45e84a
From: Deepak C Shetty <deepakcs@linux.vnet.ibm.com>
Justin M. Forbes 45e84a
Date: Sun, 4 Dec 2011 22:35:28 +0530
Justin M. Forbes 45e84a
Subject: [PATCH 05/25] hw/9pfs: Reset server state during TVERSION
Justin M. Forbes 45e84a
Justin M. Forbes 45e84a
As per the 9p rfc, during TVERSION its necessary to clean all the active
Justin M. Forbes 45e84a
fids, so that we start the session from a clean state. Its also needed in
Justin M. Forbes 45e84a
scenarios where the guest is booting off 9p, and boot fails, and client
Justin M. Forbes 45e84a
restarts, without any knowledge of the past, it will issue a TVERSION again
Justin M. Forbes 45e84a
so this ensures that we always start from a clean state.
Justin M. Forbes 45e84a
Justin M. Forbes 45e84a
Signed-off-by: Deepak C Shetty <deepakcs@linux.vnet.ibm.com>
Justin M. Forbes 45e84a
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Justin M. Forbes 45e84a
---
Justin M. Forbes 45e84a
 hw/9pfs/virtio-9p.c |   26 ++++++++++++++++++++++++++
Justin M. Forbes 45e84a
 1 files changed, 26 insertions(+), 0 deletions(-)
Justin M. Forbes 45e84a
Justin M. Forbes 45e84a
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c
Justin M. Forbes 45e84a
index 32b98dd..dd43209 100644
Justin M. Forbes 45e84a
--- a/hw/9pfs/virtio-9p.c
Justin M. Forbes 45e84a
+++ b/hw/9pfs/virtio-9p.c
Justin M. Forbes 45e84a
@@ -523,6 +523,30 @@ static int v9fs_mark_fids_unreclaim(V9fsPDU *pdu, V9fsPath *path)
Justin M. Forbes 45e84a
     return 0;
Justin M. Forbes 45e84a
 }
Justin M. Forbes 45e84a
Justin M. Forbes 45e84a
+static void virtfs_reset(V9fsPDU *pdu)
Justin M. Forbes 45e84a
+{
Justin M. Forbes 45e84a
+    V9fsState *s = pdu->s;
Justin M. Forbes 45e84a
+    V9fsFidState *fidp = NULL;
Justin M. Forbes 45e84a
+
Justin M. Forbes 45e84a
+    /* Free all fids */
Justin M. Forbes 45e84a
+    while (s->fid_list) {
Justin M. Forbes 45e84a
+        fidp = s->fid_list;
Justin M. Forbes 45e84a
+        s->fid_list = fidp->next;
Justin M. Forbes 45e84a
+
Justin M. Forbes 45e84a
+        if (fidp->ref) {
Justin M. Forbes 45e84a
+            fidp->clunked = 1;
Justin M. Forbes 45e84a
+        } else {
Justin M. Forbes 45e84a
+            free_fid(pdu, fidp);
Justin M. Forbes 45e84a
+        }
Justin M. Forbes 45e84a
+    }
Justin M. Forbes 45e84a
+    if (fidp) {
Justin M. Forbes 45e84a
+        /* One or more unclunked fids found... */
Justin M. Forbes 45e84a
+        error_report("9pfs:%s: One or more uncluncked fids "
Justin M. Forbes 45e84a
+                     "found during reset", __func__);
Justin M. Forbes 45e84a
+    }
Justin M. Forbes 45e84a
+    return;
Justin M. Forbes 45e84a
+}
Justin M. Forbes 45e84a
+
Justin M. Forbes 45e84a
 #define P9_QID_TYPE_DIR         0x80
Justin M. Forbes 45e84a
 #define P9_QID_TYPE_SYMLINK     0x02
Justin M. Forbes 45e84a
Justin M. Forbes 45e84a
@@ -1196,6 +1220,8 @@ static void v9fs_version(void *opaque)
Justin M. Forbes 45e84a
     pdu_unmarshal(pdu, offset, "ds", &s->msize, &version);
Justin M. Forbes 45e84a
     trace_v9fs_version(pdu->tag, pdu->id, s->msize, version.data);
Justin M. Forbes 45e84a
Justin M. Forbes 45e84a
+    virtfs_reset(pdu);
Justin M. Forbes 45e84a
+
Justin M. Forbes 45e84a
     if (!strcmp(version.data, "9P2000.u")) {
Justin M. Forbes 45e84a
         s->proto_version = V9FS_PROTO_2000U;
Justin M. Forbes 45e84a
     } else if (!strcmp(version.data, "9P2000.L")) {
Justin M. Forbes 45e84a
-- 
Justin M. Forbes 45e84a
1.7.7.5
Justin M. Forbes 45e84a