Skip to content

Commit

Permalink
ceph-disk: implement 'activate-journal'
Browse files Browse the repository at this point in the history
Activate an osd via its journal device.  udev populates its symlinks and
triggers events in an order that is not related to whether the device is
an osd data partition or a journal.  That means that triggering
'ceph-disk activate' can happen before the journal (or journal symlink)
is present and then fail.

Similarly, it may be that they are on different disks that are hotplugged
with the journal second.

This can be wired up to the journal partition type to ensure that osds are
started when the journal appears second.

Include the udev rules to trigger this.

Signed-off-by: Sage Weil <[email protected]>
  • Loading branch information
Sage Weil committed Jun 14, 2013
1 parent 8b3b59e commit a2a78e8
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
82 changes: 82 additions & 0 deletions src/ceph-disk
Original file line number Diff line number Diff line change
Expand Up @@ -1606,6 +1606,64 @@ def main_activate(args):
activate_lock.release()


###########################

def get_journal_osd_uuid(path):
if not os.path.exists(path):
raise Error('%s does not exist', path)

mode = os.stat(path).st_mode
if not stat.S_ISBLK(mode):
raise Error('%s is not a block device', path)

try:
out = _check_output(
args=[
'ceph-osd',
'-i', '0', # this is ignored
'--get-journal-uuid',
'--osd-journal',
path,
],
close_fds=True,
)
except subprocess.CalledProcessError as e:
raise Error(
'failed to get osd uuid/fsid from journal',
e,
)
value = str(out).split('\n', 1)[0]
LOG.debug('Journal %s has OSD UUID %s', path, value)
return value

def main_activate_journal(args):
if not os.path.exists(args.dev):
raise Error('%s does not exist', args.dev)

cluster = None
osd_id = None
osd_uuid = None
activate_lock.acquire()
try:
osd_uuid = get_journal_osd_uuid(args.dev)
path = os.path.join('/dev/disk/by-partuuid/', osd_uuid.lower())

(cluster, osd_id) = mount_activate(
dev=path,
activate_key_template=args.activate_key_template,
init=args.mark_init,
)

start_daemon(
cluster=cluster,
osd_id=osd_id,
)

activate_lock.release()

except:
activate_lock.release()
raise

###########################

Expand Down Expand Up @@ -1986,6 +2044,30 @@ def parse_args():
func=main_activate,
)

activate_journal_parser = subparsers.add_parser('activate-journal', help='Activate an OSD via its journal device')
activate_journal_parser.add_argument(
'dev',
metavar='DEV',
help='path to journal block device',
)
activate_journal_parser.add_argument(
'--activate-key',
metavar='PATH',
help='bootstrap-osd keyring path template (%(default)s)',
dest='activate_key_template',
)
activate_journal_parser.add_argument(
'--mark-init',
metavar='INITSYSTEM',
help='init system to manage this dir',
default='auto',
choices=INIT_SYSTEMS,
)
activate_journal_parser.set_defaults(
activate_key_template='/var/lib/ceph/bootstrap-osd/{cluster}.keyring',
func=main_activate_journal,
)

list_parser = subparsers.add_parser('list', help='List disks, partitions, and Ceph OSDs')
list_parser.set_defaults(
func=main_list,
Expand Down
6 changes: 6 additions & 0 deletions udev/95-ceph-osd.rules
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ ACTION=="add", SUBSYSTEM=="block", \
ENV{ID_PART_ENTRY_TYPE}=="4fbd7e29-9d25-41b8-afd0-062c0ceff05d", \
RUN+="/usr/sbin/ceph-disk-activate --mount /dev/$name"

# activate ceph-tagged partitions
ACTION=="add", SUBSYSTEM=="block", \
ENV{DEVTYPE}=="partition", \
ENV{ID_PART_ENTRY_TYPE}=="45b0969e-9b03-4f30-b4c6-b4b80ceff106", \
RUN+="/usr/sbin/ceph-disk activate-journal /dev/$name"

# Map journal if using dm-crypt
ACTION=="add" SUBSYSTEM=="block", \
ENV{DEVTYPE}=="partition", \
Expand Down

0 comments on commit a2a78e8

Please sign in to comment.