summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Mick <dan.mick@inktank.com>2013-06-13 19:37:37 -0700
committerDan Mick <dan.mick@inktank.com>2013-06-13 19:37:37 -0700
commitc672b777f8093a652b96e5913d78eba5504f8ac7 (patch)
treeb10d447e07c593ce732884252dff91ef2c3055ac
parent02599c43b4290f5474a6c4295d6caf6774ffceb1 (diff)
parenta2a78e8d16db0a71b13fc15457abc5fe0091c84c (diff)
downloadceph-c672b777f8093a652b96e5913d78eba5504f8ac7.tar.gz
Merge pull request #362 from ceph/wip-4984
ceph-disk: udev/partprobe redo, zap command, activate-journal command
-rwxr-xr-xsrc/ceph-disk140
-rw-r--r--udev/95-ceph-osd.rules6
2 files changed, 115 insertions, 31 deletions
diff --git a/src/ceph-disk b/src/ceph-disk
index 0389b5ce55b..13d9f8203ce 100755
--- a/src/ceph-disk
+++ b/src/ceph-disk
@@ -761,14 +761,6 @@ def prepare_journal_dev(
# wait for udev event queue to clear
'udevadm',
'settle',
- '--timeout=10',
- ],
- )
- subprocess.check_call(
- args=[
- # also make sure the kernel refreshes the new table
- 'partprobe',
- journal,
],
)
@@ -963,14 +955,6 @@ def prepare_dev(
# wait for udev event queue to clear
'udevadm',
'settle',
- '--timeout=10',
- ],
- )
- subprocess.check_call(
- args=[
- # also make sure the kernel refreshes the new table
- 'partprobe',
- data,
],
)
except subprocess.CalledProcessError as e:
@@ -1037,21 +1021,6 @@ def prepare_dev(
data,
],
)
- subprocess.call(
- args=[
- # wait for udev event queue to clear
- 'udevadm',
- 'settle',
- '--timeout=10',
- ],
- )
- subprocess.check_call(
- args=[
- # also make sure the kernel refreshes the new table
- 'partprobe',
- data,
- ],
- )
except subprocess.CalledProcessError as e:
raise Error(e)
@@ -1192,6 +1161,19 @@ def main_prepare(args):
raise Error('not a dir or block device', args.data)
prepare_lock.release()
+ if stat.S_ISBLK(dmode):
+ # try to make sure the kernel refreshes the table. note
+ # that if this gets ebusy, we are probably racing with
+ # udev because it already updated it.. ignore failure here.
+ LOG.debug('Calling partprobe on prepared device %s', args.data)
+ subprocess.call(
+ args=[
+ 'partprobe',
+ args.data,
+ ],
+ )
+
+
except Error as e:
if journal_dm_keypath:
os.unlink(journal_dm_keypath)
@@ -1624,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
###########################
@@ -1869,6 +1909,9 @@ def main_suppress(args):
def main_unsuppress(args):
unset_suppress(args.path)
+def main_zap(args):
+ for dev in args.dev:
+ zap(dev)
###########################
@@ -2001,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,
@@ -2028,6 +2095,17 @@ def parse_args():
func=main_unsuppress,
)
+ zap_parser = subparsers.add_parser('zap', help='Zap/erase/destroy a device\'s partition table (and contents)')
+ zap_parser.add_argument(
+ 'dev',
+ metavar='DEV',
+ nargs='*',
+ help='path to block device',
+ )
+ zap_parser.set_defaults(
+ func=main_zap,
+ )
+
args = parser.parse_args()
return args
diff --git a/udev/95-ceph-osd.rules b/udev/95-ceph-osd.rules
index 77e6ef37c5d..9798e648483 100644
--- a/udev/95-ceph-osd.rules
+++ b/udev/95-ceph-osd.rules
@@ -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", \