]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: properly extract osd fsid during adoption
authorSage Weil <sage@redhat.com>
Fri, 13 Dec 2019 23:14:12 +0000 (17:14 -0600)
committerSage Weil <sage@redhat.com>
Sun, 15 Dec 2019 00:12:49 +0000 (18:12 -0600)
This needs to be passed to the deploy_daemon_units method so that we can
set up the pre and post c-v calls properly.

Signed-off-by: Sage Weil <sage@redhat.com>
src/cephadm/cephadm

index b006954dceada23d04a4aaa23c752bf6a306bca5..b3ee79e1161e6b0d1c135275e72fddc9db58e60e 100755 (executable)
@@ -599,8 +599,9 @@ def extract_uid_gid():
     return (int(uid), int(gid))
 
 def deploy_daemon(fsid, daemon_type, daemon_id, c, uid, gid,
-                  config, keyring):
-    # type: (str, str, Union[int, str], CephContainer, int, int, Optional[str], Optional[str]) -> None
+                  config, keyring,
+                  osd_fsid=None):
+    # type: (str, str, Union[int, str], CephContainer, int, int, Optional[str], Optional[str], Optional[str]) -> None
     if daemon_type == 'mon' and not os.path.exists(
             get_data_dir(fsid, 'mon', daemon_id)):
         assert config
@@ -644,23 +645,26 @@ def deploy_daemon(fsid, daemon_type, daemon_id, c, uid, gid,
             uid, gid,
             config, keyring)
 
-    deploy_daemon_units(fsid, uid, gid, daemon_type, daemon_id, c)
+    deploy_daemon_units(fsid, uid, gid, daemon_type, daemon_id, c,
+                        osd_fsid=osd_fsid)
     update_firewalld(daemon_type)
 
 def deploy_daemon_units(fsid, uid, gid, daemon_type, daemon_id, c,
-                        enable=True, start=True):
-    # type: (str, int, int, str, Union[int, str], CephContainer, bool, bool) -> None
+                        enable=True, start=True,
+                        osd_fsid=None):
+    # type: (str, int, int, str, Union[int, str], CephContainer, bool, bool, Optional[str]) -> None
     # cmd
     data_dir = get_data_dir(fsid, daemon_type, daemon_id)
     with open(data_dir + '/unit.run', 'w') as f:
         if daemon_type == 'osd':
             # osds have a pre-start step
+            assert osd_fsid
             prestart = CephContainer(
                 image=args.image,
                 entrypoint='/usr/sbin/ceph-volume',
                 args=[
                     'lvm', 'activate',
-                    str(daemon_id), args.osd_fsid,
+                    str(daemon_id), osd_fsid,
                     '--no-systemd'
                 ],
                 container_args=['--privileged'],
@@ -672,12 +676,13 @@ def deploy_daemon_units(fsid, uid, gid, daemon_type, daemon_id, c,
         os.fchmod(f.fileno(), 0o600)
     with open(data_dir + '/unit.poststop', 'w') as f:
         if daemon_type == 'osd':
+            assert osd_fsid
             poststop = CephContainer(
                 image=args.image,
                 entrypoint='/usr/sbin/ceph-volume',
                 args=[
                     'lvm', 'deactivate',
-                    str(daemon_id), args.osd_fsid,
+                    str(daemon_id), osd_fsid,
                     '--no-systemd'
                 ],
                 container_args=['--privileged'],
@@ -1367,7 +1372,8 @@ def command_deploy():
     (uid, gid) = extract_uid_gid()
     c = get_container(args.fsid, daemon_type, daemon_id)
     deploy_daemon(args.fsid, daemon_type, daemon_id, c, uid, gid,
-                  config, keyring)
+                  config, keyring,
+                  osd_fsid=args.osd_fsid)
     if crash_keyring:
         deploy_crash(args.fsid, uid, gid, config, crash_keyring)
 
@@ -1629,6 +1635,19 @@ def command_adopt():
         if not fsid:
             raise Error('could not detect legacy fsid; set fsid in ceph.conf')
 
+        data_dir_src = ('/var/lib/ceph/%s/%s-%s' %
+                        (daemon_type, args.cluster, daemon_id))
+        data_dir_src = os.path.abspath(args.legacy_dir + data_dir_src)
+
+        osd_fsid = None
+        if daemon_type == 'osd':
+            path = os.path.join(data_dir_src, 'fsid')
+            try:
+                with open(path, 'r') as f:
+                    osd_fsid = f.read().strip()
+            except IOError:
+                raise Error('unable to read OSD fsid from %s' % path)
+
         # NOTE: implicit assumption here that the units correspond to the
         # cluster we are adopting based on the /etc/{defaults,sysconfig}/ceph
         # CLUSTER field.
@@ -1644,9 +1663,6 @@ def command_adopt():
 
         # data
         logger.info('Moving data...')
-        data_dir_src = ('/var/lib/ceph/%s/%s-%s' %
-                        (daemon_type, args.cluster, daemon_id))
-        data_dir_src = os.path.abspath(args.legacy_dir + data_dir_src)
         data_dir_dst = make_data_dir(fsid, daemon_type, daemon_id,
                                      uid=uid, gid=gid)
         move_files(glob(os.path.join(data_dir_src, '*')),
@@ -1677,7 +1693,8 @@ def command_adopt():
         c = get_container(fsid, daemon_type, daemon_id)
         deploy_daemon_units(fsid, uid, gid, daemon_type, daemon_id, c,
                             enable=True,  # unconditionally enable the new unit
-                            start=(state == 'running'))
+                            start=(state == 'running'),
+                            osd_fsid=osd_fsid)
         update_firewalld(daemon_type)
 
     else: