changeset 4a501e0f7540 in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=4a501e0f7540
description:
dev: Add support for 9p proxying over VirtIO
This patch adds support for 9p filesystem proxying over VirtIO. It can
currently operate by connecting to a 9p server over a socket
(VirtIO9PSocket) or by starting the diod 9p server and connecting over
pipe (VirtIO9PDiod).
*WARNING*: Checkpoints are currently not supported for systems with 9p
proxies!
diffstat:
src/dev/virtio/SConscript | 4 +
src/dev/virtio/VirtIO9P.py | 70 ++++++
src/dev/virtio/fs9p.cc | 481 +++++++++++++++++++++++++++++++++++++++++++++
src/dev/virtio/fs9p.hh | 371 ++++++++++++++++++++++++++++++++++
4 files changed, 926 insertions(+), 0 deletions(-)
diffs (truncated from 955 to 300 lines):
diff -r 28bc070b5a86 -r 4a501e0f7540 src/dev/virtio/SConscript
--- a/src/dev/virtio/SConscript Sat Sep 20 17:17:53 2014 -0400
+++ b/src/dev/virtio/SConscript Sat Sep 20 17:17:54 2014 -0400
@@ -45,13 +45,17 @@
SimObject('VirtIO.py')
SimObject('VirtIOConsole.py')
SimObject('VirtIOBlock.py')
+SimObject('VirtIO9P.py')
Source('base.cc')
Source('pci.cc')
Source('console.cc')
Source('block.cc')
+Source('fs9p.cc')
DebugFlag('VIO', 'VirtIO base functionality')
DebugFlag('VIOPci', 'VirtIO PCI transport')
DebugFlag('VIOConsole', 'VirtIO console device')
DebugFlag('VIOBlock', 'VirtIO block device')
+DebugFlag('VIO9P', 'General 9p over VirtIO debugging')
+DebugFlag('VIO9PData', 'Dump data in VirtIO 9p connections')
diff -r 28bc070b5a86 -r 4a501e0f7540 src/dev/virtio/VirtIO9P.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/dev/virtio/VirtIO9P.py Sat Sep 20 17:17:54 2014 -0400
@@ -0,0 +1,70 @@
+# -*- mode:python -*-
+
+# Copyright (c) 2014 ARM Limited
+# All rights reserved.
+#
+# The license below extends only to copyright in the software and shall
+# not be construed as granting a license to any other intellectual
+# property including but not limited to intellectual property relating
+# to a hardware implementation of the functionality of the software
+# licensed hereunder. You may use the software subject to the license
+# terms below provided that you ensure that this notice is replicated
+# unmodified and in its entirety in all distributions of the software,
+# modified or unmodified, in source code or in binary form.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# Authors: Andreas Sandberg
+
+from m5.params import *
+from m5.proxy import *
+from VirtIO import VirtIODeviceBase
+
+class VirtIO9PBase(VirtIODeviceBase):
+ type = 'VirtIO9PBase'
+ abstract = True
+ cxx_header = 'dev/virtio/fs9p.hh'
+
+ queueSize = Param.Unsigned(32, "Output queue size (pages)")
+ tag = Param.String("gem5", "Mount tag")
+
+
+class VirtIO9PProxy(VirtIO9PBase):
+ type = 'VirtIO9PProxy'
+ abstract = True
+ cxx_header = 'dev/virtio/fs9p.hh'
+
+class VirtIO9PDiod(VirtIO9PProxy):
+ type = 'VirtIO9PDiod'
+ cxx_header = 'dev/virtio/fs9p.hh'
+
+ diod = Param.String("/usr/sbin/diod", "Path to diod")
+ root = Param.String("/tmp", "Path to export through diod")
+
+class VirtIO9PSocket(VirtIO9PProxy):
+ type = 'VirtIO9PSocket'
+ cxx_header = 'dev/virtio/fs9p.hh'
+
+ server = Param.String("127.0.0.1", "9P server address or host name")
+ port = Param.String("564", "9P server port")
diff -r 28bc070b5a86 -r 4a501e0f7540 src/dev/virtio/fs9p.cc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/dev/virtio/fs9p.cc Sat Sep 20 17:17:54 2014 -0400
@@ -0,0 +1,481 @@
+/*
+ * Copyright (c) 2014 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Andreas Sandberg
+ */
+
+#include <netinet/in.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <netdb.h>
+#include <unistd.h>
+
+#include "debug/VIO9P.hh"
+#include "debug/VIO9PData.hh"
+#include "dev/virtio/fs9p.hh"
+#include "params/VirtIO9PBase.hh"
+#include "params/VirtIO9PDiod.hh"
+#include "params/VirtIO9PProxy.hh"
+#include "params/VirtIO9PSocket.hh"
+#include "sim/system.hh"
+
+struct P9MsgInfo {
+ P9MsgInfo(P9MsgType _type, std::string _name)
+ : type(_type), name(_name) {}
+
+ P9MsgType type;
+ std::string name;
+};
+
+typedef std::map<P9MsgType, P9MsgInfo> P9MsgInfoMap;
+
+#define P9MSG(type, name) \
+ { (type), P9MsgInfo((type), "T" # name ) }, \
+ { (type + 1), P9MsgInfo((type + 1), "R" # name ) }
+
+static const P9MsgInfoMap p9_msg_info {
+ P9MSG(6, LERROR),
+ P9MSG(8, STATFS),
+ P9MSG(12, LOPEN),
+ P9MSG(14, LCREATE),
+ P9MSG(16, SYMLINK),
+ P9MSG(18, MKNOD),
+ P9MSG(20, RENAME),
+ P9MSG(22, READLINK),
+ P9MSG(24, GETATTR),
+ P9MSG(26, SETATTR),
+ P9MSG(30, XATTRWALK),
+ P9MSG(32, XATTRCREATE),
+ P9MSG(40, READDIR),
+ P9MSG(50, FSYNC),
+ P9MSG(52, LOCK),
+ P9MSG(54, GETLOCK),
+ P9MSG(70, LINK),
+ P9MSG(72, MKDIR),
+ P9MSG(74, RENAMEAT),
+ P9MSG(76, UNLINKAT),
+ P9MSG(100, VERSION),
+ P9MSG(102, AUTH),
+ P9MSG(104, ATTACH),
+ P9MSG(106, ERROR),
+ P9MSG(108, FLUSH),
+ P9MSG(110, WALK),
+ P9MSG(112, OPEN),
+ P9MSG(114, CREATE),
+ P9MSG(116, READ),
+ P9MSG(118, WRITE),
+ P9MSG(120, CLUNK),
+ P9MSG(122, REMOVE),
+ P9MSG(124, STAT),
+ P9MSG(126, WSTAT),
+};
+
+#undef P9MSG
+
+VirtIO9PBase::VirtIO9PBase(Params *params)
+ : VirtIODeviceBase(params, ID_9P,
+ sizeof(Config) + params->tag.size(),
+ F_MOUNT_TAG),
+ queue(params->system->physProxy, params->queueSize, *this)
+{
+ config.reset((Config *)
+ operator new(configSize));
+ config->len = htov_legacy(params->tag.size());
+ memcpy(config->tag, params->tag.c_str(), params->tag.size());
+
+ registerQueue(queue);
+}
+
+
+VirtIO9PBase::~VirtIO9PBase()
+{
+}
+
+void
+VirtIO9PBase::readConfig(PacketPtr pkt, Addr cfgOffset)
+{
+ readConfigBlob(pkt, cfgOffset, (uint8_t *)config.get());
+}
+
+void
+VirtIO9PBase::FSQueue::onNotifyDescriptor(VirtDescriptor *desc)
+{
+ DPRINTF(VIO9P, "Got input data descriptor (len: %i)\n", desc->size());
+ DPRINTF(VIO9P, "\tPending transactions: %i\n",
parent.pendingTransactions.size());
+
+ P9MsgHeader header;
+ desc->chainRead(0, (uint8_t *)&header, sizeof(header));
+ header = p9toh(header);
+
+ uint8_t data[header.len - sizeof(header)];
+ desc->chainRead(sizeof(header), data, sizeof(data));
+
+ // Keep track of pending transactions
+ parent.pendingTransactions[header.tag] = desc;
+
+ DPRINTF(VIO9P, "recvTMsg\n");
+ parent.dumpMsg(header, data, sizeof(data));
+
+ // Notify device of message
+ parent.recvTMsg(header, data, sizeof(data));
+}
+
+void
+VirtIO9PBase::sendRMsg(const P9MsgHeader &header, const uint8_t *data, size_t
size)
+{
+ DPRINTF(VIO9P, "Sending RMsg\n");
+ dumpMsg(header, data, size);
+ DPRINTF(VIO9P, "\tPending transactions: %i\n", pendingTransactions.size());
+ assert(header.len >= sizeof(header));
+
+ VirtDescriptor *main_desc(pendingTransactions[header.tag]);
+ pendingTransactions.erase(header.tag);
+
+ // Find the first output descriptor
+ VirtDescriptor *out_desc(main_desc);
+ while (out_desc && !out_desc->isOutgoing())
+ out_desc = out_desc->next();
+ if (!out_desc)
+ panic("sendRMsg: Framing error, no output descriptor.\n");
+
+ P9MsgHeader header_out(htop9(header));
+ header_out.len = htop9(sizeof(P9MsgHeader) + size);
+
+ out_desc->chainWrite(0, (uint8_t *)&header_out, sizeof(header_out));
+ out_desc->chainWrite(sizeof(header_out), data, size);
+
+ queue.produceDescriptor(main_desc, sizeof(P9MsgHeader) + size);
+ kick();
+}
+
+void
+VirtIO9PBase::dumpMsg(const P9MsgHeader &header, const uint8_t *data, size_t
size)
+{
+#ifndef NDEBUG
+ if (!DTRACE(VIO9P))
+ return;
+
+ const P9MsgInfoMap::const_iterator it_msg(p9_msg_info.find(header.type));
+ if (it_msg != p9_msg_info.cend()) {
+ const P9MsgInfo &info(it_msg->second);
+ DPRINTF(VIO9P, "P9Msg[len = %i, type = %s (%i), tag = %i]\n",
+ header.len, info.name, header.type, header.tag);
+ } else {
+ DPRINTF(VIO9P, "P9Msg[len = %i, type = Unknown (%i), tag = %i]\n",
+ header.len, header.type, header.tag);
+ }
+ DDUMP(VIO9PData, data, size);
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev