summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTommi Virtanen <tv@inktank.com>2012-10-02 16:37:07 -0700
committerTommi Virtanen <tv@inktank.com>2012-10-05 15:43:18 -0700
commitce5e1f8dfaa8675b0a1e9fa22ebf91be9652aa01 (patch)
tree0194033df4ad6a11a26df8f1690a9fe6ad1d98c0
parentda86e4e43676ceaf0b39635954489c297de88025 (diff)
downloadceph-ce5e1f8dfaa8675b0a1e9fa22ebf91be9652aa01.tar.gz
ceph-disk-activate: Unmount on errors (if it did the mount).
This cleans up the error handling to not leave disks mounted in /var/lib/ceph/tmp/mnt.* when something fails, e.g. when the ceph command line tool can't talk to mons. Signed-off-by: Tommi Virtanen <tv@inktank.com>
-rwxr-xr-xsrc/ceph-disk-activate133
1 files changed, 78 insertions, 55 deletions
diff --git a/src/ceph-disk-activate b/src/ceph-disk-activate
index 225e2a664ea..e0bfb0f6c39 100755
--- a/src/ceph-disk-activate
+++ b/src/ceph-disk-activate
@@ -57,6 +57,12 @@ class MountError(ActivateError):
"""
+class UnmountError(ActivateError):
+ """
+ Unmounting filesystem failed
+ """
+
+
def maybe_mkdir(*a, **kw):
try:
os.mkdir(*a, **kw)
@@ -354,74 +360,91 @@ def mount(
return path
+def unmount(
+ path,
+ ):
+ try:
+ subprocess.check_call(
+ args=[
+ 'umount',
+ '--',
+ path,
+ ],
+ )
+ except subprocess.CalledProcessError as e:
+ raise UnmountError(e)
+
+
def activate(
path,
activate_key_template,
do_mount,
):
+
if do_mount:
path = mount(dev=path)
- # TODO unmount on errors?
-
- check_osd_magic(path)
-
- ceph_fsid = read_one_line(path, 'ceph_fsid')
- if ceph_fsid is None:
- raise ActivateError('No cluster uuid assigned.')
- log.debug('Cluster uuid is %s', ceph_fsid)
-
- # TODO use ceph_fsid to find the right cluster
- cluster = 'ceph'
- log.debug('Cluster name is %s', cluster)
-
- fsid = read_one_line(path, 'fsid')
- if fsid is None:
- raise ActivateError('No OSD uuid assigned.')
- log.debug('OSD uuid is %s', fsid)
-
- keyring = activate_key_template.format(cluster=cluster)
-
- osd_id = get_osd_id(path)
- if osd_id is None:
- osd_id = allocate_osd_id(
- cluster=cluster,
- fsid=fsid,
- keyring=keyring,
- )
- write_one_line(path, 'whoami', osd_id)
- log.debug('OSD id is %s', osd_id)
-
- if not os.path.exists(os.path.join(path, 'ready')):
- log.debug('Initializing OSD...')
- # re-running mkfs is safe, so just run until it completes
- mkfs(
- path=path,
- cluster=cluster,
- osd_id=osd_id,
- fsid=fsid,
- keyring=keyring,
- )
+ try:
+ check_osd_magic(path)
+
+ ceph_fsid = read_one_line(path, 'ceph_fsid')
+ if ceph_fsid is None:
+ raise ActivateError('No cluster uuid assigned.')
+ log.debug('Cluster uuid is %s', ceph_fsid)
+
+ # TODO use ceph_fsid to find the right cluster
+ cluster = 'ceph'
+ log.debug('Cluster name is %s', cluster)
+
+ fsid = read_one_line(path, 'fsid')
+ if fsid is None:
+ raise ActivateError('No OSD uuid assigned.')
+ log.debug('OSD uuid is %s', fsid)
+
+ keyring = activate_key_template.format(cluster=cluster)
+
+ osd_id = get_osd_id(path)
+ if osd_id is None:
+ osd_id = allocate_osd_id(
+ cluster=cluster,
+ fsid=fsid,
+ keyring=keyring,
+ )
+ write_one_line(path, 'whoami', osd_id)
+ log.debug('OSD id is %s', osd_id)
+
+ if not os.path.exists(os.path.join(path, 'ready')):
+ log.debug('Initializing OSD...')
+ # re-running mkfs is safe, so just run until it completes
+ mkfs(
+ path=path,
+ cluster=cluster,
+ osd_id=osd_id,
+ fsid=fsid,
+ keyring=keyring,
+ )
+
+ if not os.path.exists(os.path.join(path, 'active')):
+ log.debug('Authorizing OSD key...')
+ auth_key(
+ path=path,
+ cluster=cluster,
+ osd_id=osd_id,
+ keyring=keyring,
+ )
+ write_one_line(path, 'active', 'ok')
- if not os.path.exists(os.path.join(path, 'active')):
- log.debug('Authorizing OSD key...')
- auth_key(
+ move_mount(
path=path,
cluster=cluster,
osd_id=osd_id,
- keyring=keyring,
)
- write_one_line(path, 'active', 'ok')
-
- move_mount(
- path=path,
- cluster=cluster,
- osd_id=osd_id,
- )
-
- if do_mount:
- # if we created a temp dir to mount it, remove it
- os.rmdir(path)
+ except:
+ unmount(path)
+ finally:
+ if do_mount:
+ # if we created a temp dir to mount it, remove it
+ os.rmdir(path)
upstart_start(
cluster=cluster,