From patchwork Fri Jun 21 15:17:09 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Barbe X-Patchwork-Id: 2763281 Return-Path: X-Original-To: patchwork-ceph-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1E10CC0AB1 for ; Fri, 21 Jun 2013 15:17:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 94CB920284 for ; Fri, 21 Jun 2013 15:17:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EB52620279 for ; Fri, 21 Jun 2013 15:17:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1423159Ab3FUPRP (ORCPT ); Fri, 21 Jun 2013 11:17:15 -0400 Received: from mail-wg0-f45.google.com ([74.125.82.45]:57289 "EHLO mail-wg0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423118Ab3FUPRP (ORCPT ); Fri, 21 Jun 2013 11:17:15 -0400 Received: by mail-wg0-f45.google.com with SMTP id j13so6677343wgh.12 for ; Fri, 21 Jun 2013 08:17:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:x-gm-message-state; bh=wCvVjwpu8ODUT78RncIelLoxi6PDXlsXoV3pgAGJ7t0=; b=GUIfEOASEMzrJmGL3bO85YQP8Zym9eaQKtGOTcESGdYIwukbibmOG5sg8hmCfrOxC3 VHqT3rj3cxp5pWy6Fy2N5K/d38efDopxol8HkPIF/Dk7vjeBdw5EMlwh3XPWG37ypuh7 GD3Va2YHNVvPNC3+BBR9XQfFTUNyPm5UH+mAWVYkB7yZTI3khaCkAMX269IiCeO0w2Xy JI3h7YN5i31PYVql5wTcAhhcaF5W9b1bLtIWojA3xP+db8o3A1w+jM1l0FKQJbDXGDwp x8aIMUpKa5kV5u0TnnUfsie61H94dE/uDjkdGYAGW1Tgg9qQauwWLzZQXVuBeRpSa971 J//A== X-Received: by 10.194.19.3 with SMTP id a3mr9748927wje.54.1371827833927; Fri, 21 Jun 2013 08:17:13 -0700 (PDT) Received: from BENCH971 (cse35-1-82-236-141-76.fbx.proxad.net. [82.236.141.76]) by mx.google.com with ESMTPSA id o14sm23612522wiv.3.2013.06.21.08.17.12 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 21 Jun 2013 08:17:12 -0700 (PDT) Received: by BENCH971 (Postfix, from userid 1000) id 34CA09A008B; Fri, 21 Jun 2013 17:17:11 +0200 (CEST) From: Laurent Barbe To: ceph-devel@vger.kernel.org Cc: Laurent Barbe Subject: [PATCH] Add rc script for rbd map/unmap Date: Fri, 21 Jun 2013 17:17:09 +0200 Message-Id: <1371827829-1025-1-git-send-email-laurent@ksperis.com> X-Mailer: git-send-email 1.8.1.2 X-Gm-Message-State: ALoCoQm6tM7/+9sIenkN9uiiCZSsTi0rv4WLDINOsvGqXLNNn8VoGVPicqa9iM6Saw71oKEsgXmJ Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Init script for mapping/unmapping rbd device on startup and shutdown. On start, map rbd dev according to /etc/rbdmap, and force mount -a On stop, umount file system depending on rbd and unmap all rbd Since some distribution use symlink for /etc/mtab, the user-space attribute _netdev is not enough to umount file system before rbd dev. (also concern: #1790) Signed-off-by: Laurent Barbe --- src/init-rbdmap | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/rbdmap | 3 ++ 2 files changed, 106 insertions(+) create mode 100755 src/init-rbdmap create mode 100644 src/rbdmap diff --git a/src/init-rbdmap b/src/init-rbdmap new file mode 100755 index 0000000..a2187ce --- /dev/null +++ b/src/init-rbdmap @@ -0,0 +1,103 @@ +#!/bin/bash + +### BEGIN INIT INFO +# Provides: rbdmap +# Required-Start: $network +# Required-Stop: $network +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Ceph RBD Mapping +# Description: Ceph RBD Mapping +### END INIT INFO + +DESC="RBD Mapping" +RBDMAPFILE="/etc/rbdmap" + +. /lib/lsb/init-functions + +do_map() { + if [ ! -f "$RBDMAPFILE" ]; then + log_warning_msg "$DESC : No $RBDMAPFILE found." + exit 0 + fi + + log_daemon_msg "Starting $DESC" + # Read /etc/rbdtab to create non-existant mapping + newrbd= + RET=0 + while read DEV PARAMS; do + case "$DEV" in + ""|\#*) + continue + ;; + */*) + ;; + *) + DEV=rbd/$DEV + ;; + esac + OIFS=$IFS + IFS=',' + for PARAM in ${PARAMS[@]}; do + CMDPARAMS="$CMDPARAMS --$(echo $PARAM | tr '=' ' ')" + done + IFS=$OIFS + if [ ! -b /dev/rbd/$DEV ]; then + log_progress_msg $DEV + rbd map $DEV $CMDPARAMS + [ $? -ne "0" ] && RET=1 + newrbd="yes" + fi + done < $RBDMAPFILE + log_end_msg $RET + + # Mount new rbd + if [ "$newrbd" ]; then + log_action_begin_msg "Mounting all filesystems" + mount -a + log_action_end_msg $? + fi +} + +do_unmap() { + log_daemon_msg "Stopping $DESC" + RET=0 + # Unmap all rbd device + for DEV in /dev/rbd[0-9]*; do + log_progress_msg $DEV + # Umount before unmap + MNTDEP=$(findmnt --mtab --source $DEV --output TARGET | sed 1,1d | sort -r) + for MNT in $MNTDEP; do + umount $MNT || sleep 1 && umount -l $DEV + done + rbd unmap $DEV + [ $? -ne "0" ] && RET=1 + done + log_end_msg $RET +} + + +case "$1" in + start) + do_map + ;; + + stop) + do_unmap + ;; + + reload) + do_map + ;; + + status) + rbd showmapped + ;; + + *) + log_success_msg "Usage: rbdmap {start|stop|reload|status}" + exit 1 + ;; +esac + +exit 0 diff --git a/src/rbdmap b/src/rbdmap new file mode 100644 index 0000000..9d34e9e --- /dev/null +++ b/src/rbdmap @@ -0,0 +1,3 @@ +# RbdDevice Parameters +#rbd/rbddevice id=client,keyring=/etc/ceph/ceph.client.keyring +