From patchwork Wed Jan 28 22:12:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Fasheh X-Patchwork-Id: 5732361 Return-Path: X-Original-To: patchwork-ocfs2-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CAE709F399 for ; Wed, 28 Jan 2015 22:14:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E710020103 for ; Wed, 28 Jan 2015 22:14:11 +0000 (UTC) Received: from aserp1040.oracle.com (aserp1040.oracle.com [141.146.126.69]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1C8E120125 for ; Wed, 28 Jan 2015 22:14:10 +0000 (UTC) Received: from ucsinet22.oracle.com (ucsinet22.oracle.com [156.151.31.94]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t0SMDaOh020268 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 28 Jan 2015 22:13:37 GMT Received: from oss.oracle.com (oss-old-reserved.oracle.com [137.254.22.2]) by ucsinet22.oracle.com (8.14.5+Sun/8.14.5) with ESMTP id t0SMDZwB010757 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Wed, 28 Jan 2015 22:13:36 GMT Received: from localhost ([127.0.0.1] helo=lb-oss.oracle.com) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1YGarf-0005LP-HX; Wed, 28 Jan 2015 14:13:35 -0800 Received: from acsinet22.oracle.com ([141.146.126.238]) by oss.oracle.com with esmtp (Exim 4.63) (envelope-from ) id 1YGaqZ-0005Gw-Nk; Wed, 28 Jan 2015 14:12:27 -0800 Received: from aserp1030.oracle.com (aserp1030.oracle.com [141.146.126.68]) by acsinet22.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id t0SMCRgC008831 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 28 Jan 2015 22:12:27 GMT Received: from userp2030.oracle.com (userp2030.oracle.com [156.151.31.89]) by aserp1030.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t0SMCQji014094 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 28 Jan 2015 22:12:27 GMT Received: from pps.filterd (userp2030.oracle.com [127.0.0.1]) by userp2030.oracle.com (8.14.7/8.14.7) with SMTP id t0SMCCer020910; Wed, 28 Jan 2015 22:12:26 GMT Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by userp2030.oracle.com with ESMTP id 1s7847g951-1 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NOT); Wed, 28 Jan 2015 22:12:26 +0000 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id DD5A0AD8C; Wed, 28 Jan 2015 22:12:23 +0000 (UTC) From: Mark Fasheh To: ocfs2-tools-devel@oss.oracle.com, ocfs2-devel@oss.oracle.com Date: Wed, 28 Jan 2015 14:12:05 -0800 Message-Id: <1422483128-32471-4-git-send-email-mfasheh@suse.de> X-Mailer: git-send-email 2.1.2 In-Reply-To: <1422483128-32471-1-git-send-email-mfasheh@suse.de> References: <1422483128-32471-1-git-send-email-mfasheh@suse.de> X-ServerName: cantor2.suse.de X-Proofpoint-Virus-Version: vendor=nai engine=5600 definitions=7695 signatures=670622 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 suspectscore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=7.0.1-1402240000 definitions=main-1501280222 Cc: Mark Fasheh , Goldwyn Rodrigues Subject: [Ocfs2-devel] [PATCH 3/6] Auto setup cluster_stack based on what is on disk X-BeenThere: ocfs2-devel@oss.oracle.com X-Mailman-Version: 2.1.9 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ocfs2-devel-bounces@oss.oracle.com Errors-To: ocfs2-devel-bounces@oss.oracle.com X-Source-IP: ucsinet22.oracle.com [156.151.31.94] X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 From: Goldwyn Rodrigues This happens only the first time. mount.ocfs2 reads the stack from the filesystems superblock. If the stack is not setup, it will modprobe the modules and write the appropriate stack name to cluster_stack file. If it is already present, it tries to edit/re-write it, if different. If it fails, the mount fails. Signed-off-by: Goldwyn Rodrigues Signed-off-by: Mark Fasheh --- include/o2cb/o2cb.h | 1 + libo2cb/o2cb_abi.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++ mount.ocfs2/mount.ocfs2.c | 6 +++ 3 files changed, 113 insertions(+) diff --git a/include/o2cb/o2cb.h b/include/o2cb/o2cb.h index d512cf9..5ef9754 100644 --- a/include/o2cb/o2cb.h +++ b/include/o2cb/o2cb.h @@ -208,5 +208,6 @@ void o2cb_control_close(void); errcode_t o2cb_control_node_down(const char *uuid, unsigned int nodeid); errcode_t o2cb_get_hb_ctl_path(char *buf, int count); +errcode_t o2cb_setup_stack(char *stack_name); #endif /* _O2CB_H */ diff --git a/libo2cb/o2cb_abi.c b/libo2cb/o2cb_abi.c index 2867fea..4414ff2 100644 --- a/libo2cb/o2cb_abi.c +++ b/libo2cb/o2cb_abi.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -150,6 +151,22 @@ static ssize_t read_single_line_file(const char *file, char *line, return ret; } +static int write_single_line_file(char *filename, char *line, size_t count) +{ + ssize_t ret = 0; + FILE *f; + + f = fopen(filename, "w"); + if (f) { + if (fputs(line, f)) + ret = strlen(line); + fclose(f); + } else + ret = -errno; + + return ret; +} + static ssize_t read_stack_file(char *line, size_t count) { return read_single_line_file(CLUSTER_STACK_FILE, line, count); @@ -2582,3 +2599,92 @@ errcode_t o2cb_get_hb_ctl_path(char *buf, int count) return 0; } + +#define MODPROBE_COMMAND "/sbin/modprobe" +#define USER_KERNEL_MODULE "ocfs2_stack_user" +#define O2CB_KERNEL_MODULE "ocfs2_stack_o2cb" + +static int perform_modprobe(char *module_name) +{ + pid_t child; + int child_status; + + char *argv[3]; + + argv[0] = MODPROBE_COMMAND; + argv[1] = module_name; + argv[2] = NULL; + + child = fork(); + if (child == 0) { + execv(MODPROBE_COMMAND, argv); + /* If execv fails, we have a problem */ + return -EINVAL; + } else + wait(&child_status); + + return child_status; +} + +errcode_t o2cb_setup_stack(char *stack_name) +{ + char line[64]; + int modprobe_performed = 0, write_performed = 0; + errcode_t err = O2CB_ET_SERVICE_UNAVAILABLE; + int len; + +redo: + len = read_single_line_file(CLUSTER_STACK_FILE, line, sizeof(line)); + + if (len > 0) { + if (line[len - 1] == '\n') { + line[len - 1] = '\0'; + len--; + } + + if (len != OCFS2_STACK_LABEL_LEN) { + err = O2CB_ET_INTERNAL_FAILURE; + goto out; + } + + if (!strncmp(line, stack_name, OCFS2_STACK_LABEL_LEN)) { + err = 0; + goto out; + } + + if (!write_performed) { + len = write_single_line_file(CLUSTER_STACK_FILE, + stack_name, strlen(stack_name)); + if (len < 0) + goto out; + write_performed = 1; + goto redo; + } + + } else if (len == -ENOENT) { + if (!modprobe_performed) { + perform_modprobe("ocfs2"); + if ((!strncmp(stack_name, OCFS2_PCMK_CLUSTER_STACK, + OCFS2_STACK_LABEL_LEN)) || + (!strncmp(stack_name, OCFS2_CMAN_CLUSTER_STACK, + OCFS2_STACK_LABEL_LEN))) + perform_modprobe(USER_KERNEL_MODULE); + else if (!strncmp(stack_name, classic_stack.s_name, + OCFS2_STACK_LABEL_LEN)) + perform_modprobe(O2CB_KERNEL_MODULE); + + write_single_line_file(CLUSTER_STACK_FILE, stack_name, + OCFS2_STACK_LABEL_LEN); + write_performed = 1; + goto redo; + } else + err = O2CB_ET_INTERNAL_FAILURE; + } else { + err = O2CB_ET_INTERNAL_FAILURE; + goto out; + } + + err = 0; +out: + return err; +} diff --git a/mount.ocfs2/mount.ocfs2.c b/mount.ocfs2/mount.ocfs2.c index 2fa2c2f..a1c8698 100644 --- a/mount.ocfs2/mount.ocfs2.c +++ b/mount.ocfs2/mount.ocfs2.c @@ -358,6 +358,12 @@ int main(int argc, char **argv) if (verbose) printf("device=%s\n", mo.dev); + ret = o2cb_setup_stack((char *)OCFS2_RAW_SB(fs->fs_super)->s_cluster_info.ci_stack); + if (ret) { + com_err(progname, ret, "while setting up stack\n"); + goto bail; + } + if (clustered) { ret = o2cb_init(); if (ret) {