Skip to content

Commit

Permalink
WIP zfs-vol: implement sr-create 1/4: SR.create
Browse files Browse the repository at this point in the history
FIXME: pool passed through `zpool` should get a sanity check before
being accepted, and get aligned with what we otherwise create

SR can then be disposed of using "xe sr-forget" and "zpool destroy".

Underlying zpool can be either separately created and given to
SR.create, or a set of devices can be specified to create a new zpool
on.

Notes:
- `SR.attach` will be necessary to complete `sr-create`: while from a
  calling user PoV things appear to have gone fine, SMlog reveals a
  call to `SR.attach`, which naturally failed as not yet implemented.
  Any attempt to `xe pbd-plug` naturally also fails.  See
  xapi-project/xen-api#5532.
- there is no plugin feature to shield from SR.* calls

Originally-by: Matias Ezequiel Vara Larsen <[email protected]>
Signed-off-by: Yann Dirson <[email protected]>
  • Loading branch information
ydirson committed Apr 2, 2024
1 parent 1b058fc commit b15b2d2
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
54 changes: 53 additions & 1 deletion plugins/volume/org.xen.xapi.storage.zfs-vol/sr.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,68 @@
from xapi.storage.libs.libcow.volume import COWVolume
import xapi.storage.api.v5.volume

import zfsutils


@util.decorate_all_routines(util.log_exceptions_in_function)
class Implementation(xapi.storage.api.v5.volume.SR_skeleton):
"SR driver to provide volumes from zvol's"

def create(self, dbg, sr_uuid, configuration, name, description):
log.debug('{}: SR.create: config={}, sr_uuid={}'.format(
dbg, configuration, sr_uuid))

# 2 ways to create a SR:
# - from an existing zpool (manually created for complex configs)
# - from a "device" config string (comma-separated list of devices)

if 'zpool' in configuration:
if 'device' in configuration:
log.error('"zpool" specified, "device" should not be used')
raise Exception('"zpool" specified, "device" should not be used')

# FIXME validate existence of pool first?
pool_name = configuration['zpool']

elif 'device' in configuration:
devs = configuration['device'].split(',')

pool_name = "sr-{}".format(sr_uuid)
zfsutils.pool_create(dbg, pool_name, devs)

# "device" is only used once to create the zpool, which
# then becomes the sole way to designate the SR
configuration["orig-device"] = configuration['device']
del configuration['device']
configuration["zpool"] = pool_name

else:
log.error('devices config must have "zpool" or "device"')
raise Exception('devices config must have "zpool" or "device"')

# FIXME this assumes zpool is mounted/attached
mountpoint = zfsutils.pool_mountpoint(dbg, pool_name)
importlib.import_module('zfs-vol').Callbacks().create_database(mountpoint)

meta = {
'name': name,
'description': description,
'uuid': sr_uuid,
}
util.update_sr_metadata(dbg, 'file://' + mountpoint, meta)

log.debug('{}: SR.create: sr={}'.format(dbg, mountpoint))
return configuration


if __name__ == '__main__':
log.log_call_argv()
cmd = xapi.storage.api.v5.volume.SR_commandline(Implementation())

call("zfs-vol.sr", ['modprobe', 'zfs'])

base = os.path.basename(sys.argv[0])
raise xapi.storage.api.v5.volume.Unimplemented(base)
if base == 'SR.create':
cmd.create()
else:
raise xapi.storage.api.v5.volume.Unimplemented(base)
15 changes: 15 additions & 0 deletions plugins/volume/org.xen.xapi.storage.zfs-vol/zfsutils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import os

from xapi.storage.common import call

MOUNT_ROOT = '/var/run/sr-mount'

def pool_mountpoint(dbg, pool_name):
cmd = "zfs get mountpoint -H -o value".split() + [ pool_name ]
return call(dbg, cmd).strip()

def pool_create(dbg, pool_name, devs):
cmd = ("zpool create".split() + [pool_name] # FIXME '-f' ?
+ ['-R', MOUNT_ROOT]
+ devs)
call(dbg, cmd)

0 comments on commit b15b2d2

Please sign in to comment.