[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 09/15] scripts/qom-fuse: Convert to QOMCommand
From: |
John Snow |
Subject: |
[PATCH 09/15] scripts/qom-fuse: Convert to QOMCommand |
Date: |
Wed, 21 Oct 2020 14:52:02 -0400 |
Move qom-fuse onto the QOMCommand base established in
python/qemu/qmp/qom_common.py. The interface doesn't change
incompatibly, "qom-fuse mountpoint" still works as an invocation, and
QMP_SOCKET is still used as the environment variable.
Signed-off-by: John Snow <jsnow@redhat.com>
---
scripts/qmp/qom-fuse | 59 ++++++++++++++++++++++++++++++++++----------
1 file changed, 46 insertions(+), 13 deletions(-)
diff --git a/scripts/qmp/qom-fuse b/scripts/qmp/qom-fuse
index 5b80da9df6..f9bf85f382 100755
--- a/scripts/qmp/qom-fuse
+++ b/scripts/qmp/qom-fuse
@@ -8,11 +8,19 @@ may be browsed, queried and edited using traditional shell
tooling.
This script requires the 'fusepy' python package;
you may install it by using ``pip3 install --user fusepy``.
-ENV:
- QMP_SOCKET: Path to the QMP server socket
-Usage:
- qom-fuse /mount/to/here
+usage: qom-fuse [-h] [--socket SOCKET] <mount>
+
+Mount a QOM tree as a FUSE filesystem
+
+positional arguments:
+ <mount> Mount point
+
+optional arguments:
+ -h, --help show this help message and exit
+ --socket SOCKET, -s SOCKET
+ QMP socket path or address (addr:port). May also be
+ set via QMP_SOCKET environment variable.
"""
##
# Copyright IBM, Corp. 2012
@@ -26,30 +34,56 @@ Usage:
# See the COPYING file in the top-level directory.
##
+import argparse
from errno import ENOENT, EPERM
import os
import stat
import sys
+from typing import Dict
import fuse
from fuse import FUSE, FuseOSError, Operations
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
-from qemu.qmp import QEMUMonitorProtocol, QMPResponseError
+from qemu.qmp import QMPResponseError
+from qemu.qmp.qom_common import QOMCommand
fuse.fuse_python_api = (0, 2)
-class QOMFS(Operations):
- """QOMFS implements fuse.Operations to provide a QOM filesystem."""
- def __init__(self, qmp):
- self.qmp = qmp
- self.qmp.connect()
- self.ino_map = {}
+class QOMFuse(QOMCommand, Operations):
+ """
+ QOMFuse implements both fuse.Operations and QOMCommand.
+
+ Operations implements the FS, and QOMCommand implements the CLI command.
+ """
+ name = 'fuse'
+ help = 'Mount a QOM tree as a FUSE filesystem'
+ fuse: FUSE
+
+ @classmethod
+ def configure_parser(cls, parser: argparse.ArgumentParser) -> None:
+ super().configure_parser(parser)
+ parser.add_argument(
+ 'mount',
+ metavar='<mount>',
+ action='store',
+ help="Mount point",
+ )
+
+ def __init__(self, args: argparse.Namespace):
+ super().__init__(args)
+ self.mount = args.mount
+ self.ino_map: Dict[str, int] = {}
self.ino_count = 1
+ def run(self) -> int:
+ print(f"Mounting QOMFS to '{self.mount}'", file=sys.stderr)
+ self.fuse = FUSE(self, self.mount, foreground=True)
+ return 0
+
def get_ino(self, path):
"""Get an inode number for a given QOM path."""
if path in self.ino_map:
@@ -172,5 +206,4 @@ class QOMFS(Operations):
if __name__ == '__main__':
- fuse = FUSE(QOMFS(QEMUMonitorProtocol(os.environ['QMP_SOCKET'])),
- sys.argv[1], foreground=True)
+ sys.exit(QOMFuse.entry_point())
--
2.26.2
- Re: [PATCH 07/15] scripts/qom-fuse: Apply pylint rules, (continued)
- [PATCH 12/15] scripts/qom-fuse: add static type hints, John Snow, 2020/10/21
- [PATCH 11/15] scripts/qom-fuse: ensure QOMFuse.read always returns bytes, John Snow, 2020/10/21
- [PATCH 06/15] python: Add 'fh' to known-good variable names, John Snow, 2020/10/21
- [PATCH 01/15] python/qmp: Add qom script rewrites, John Snow, 2020/10/21
- [PATCH 02/15] python/qmp: add qom script entry points, John Snow, 2020/10/21
- [PATCH 04/15] scripts/qom-fuse: apply isort rules, John Snow, 2020/10/21
- [PATCH 09/15] scripts/qom-fuse: Convert to QOMCommand,
John Snow <=
- [PATCH 15/15] python: add fuse command to 'qom' tools, John Snow, 2020/10/21
- [PATCH 14/15] scripts/qom-fuse: add redirection shim to python/qemu/qmp/qom-fuse.py, John Snow, 2020/10/21
- [PATCH 05/15] scripts/qom-fuse: apply flake8 rules, John Snow, 2020/10/21