mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 16:53:55 -06:00
scripts/qom-fuse: Convert to QOMCommand
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> Message-id: 20210603003719.1321369-13-jsnow@redhat.com Signed-off-by: John Snow <jsnow@redhat.com>
This commit is contained in:
parent
187be27c7b
commit
2aa101799a
1 changed files with 46 additions and 13 deletions
|
@ -7,11 +7,19 @@ may be browsed, queried and edited using traditional shell tooling.
|
||||||
|
|
||||||
This script requires the 'fusepy' python package.
|
This script requires the 'fusepy' python package.
|
||||||
|
|
||||||
ENV:
|
|
||||||
QMP_SOCKET: Path to the QMP server socket
|
|
||||||
|
|
||||||
Usage:
|
usage: qom-fuse [-h] [--socket SOCKET] <mount>
|
||||||
qom-fuse /mount/to/here
|
|
||||||
|
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
|
# Copyright IBM, Corp. 2012
|
||||||
|
@ -25,30 +33,56 @@ Usage:
|
||||||
# See the COPYING file in the top-level directory.
|
# See the COPYING file in the top-level directory.
|
||||||
##
|
##
|
||||||
|
|
||||||
|
import argparse
|
||||||
from errno import ENOENT, EPERM
|
from errno import ENOENT, EPERM
|
||||||
import os
|
import os
|
||||||
import stat
|
import stat
|
||||||
import sys
|
import sys
|
||||||
|
from typing import Dict
|
||||||
|
|
||||||
import fuse
|
import fuse
|
||||||
from fuse import FUSE, FuseOSError, Operations
|
from fuse import FUSE, FuseOSError, Operations
|
||||||
|
|
||||||
|
|
||||||
sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', 'python'))
|
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)
|
fuse.fuse_python_api = (0, 2)
|
||||||
|
|
||||||
|
|
||||||
class QOMFS(Operations):
|
class QOMFuse(QOMCommand, Operations):
|
||||||
"""QOMFS implements fuse.Operations to provide a QOM filesystem."""
|
"""
|
||||||
def __init__(self, qmp):
|
QOMFuse implements both fuse.Operations and QOMCommand.
|
||||||
self.qmp = qmp
|
|
||||||
self.qmp.connect()
|
Operations implements the FS, and QOMCommand implements the CLI command.
|
||||||
self.ino_map = {}
|
"""
|
||||||
|
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
|
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):
|
def get_ino(self, path):
|
||||||
"""Get an inode number for a given QOM path."""
|
"""Get an inode number for a given QOM path."""
|
||||||
if path in self.ino_map:
|
if path in self.ino_map:
|
||||||
|
@ -171,5 +205,4 @@ class QOMFS(Operations):
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
fuse = FUSE(QOMFS(QEMUMonitorProtocol(os.environ['QMP_SOCKET'])),
|
sys.exit(QOMFuse.entry_point())
|
||||||
sys.argv[1], foreground=True)
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue