/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdlib.h>
#include <unistd.h>
#include <wait.h>
#include <meta.h>
#include <metad.h>
#include <mdmn_changelog.h>
#include <syslog.h>
#include <umem.h>
/*
* Number of log entries per set.
*
* We want at least 4 spares available at all times
* in case new classes are added during a live upgrade.
*
* Allocate the entries in chunks of 16
*/
/* Global variables */
/* Total number of log records */
#ifdef DEBUG
void
{
}
void
{
}
void
{
int i;
for (i = 0; i < mdmn_logrecs; i++) {
fn_name, i);
}
}
#endif
/*
* copy_changelog: copies changelog ondisk<->incore records.
* The argument "direction" controls the direction to copy the
* the records. Incore and ondisk changlog structures must be
* allocated when calling this routine.
*
* The purpose of changelog is to store a message that is in progress.
* Therefore the changlog structure embeds the message structure.
* Incore and ondisk changelog structures are created to handle the
* incore and ondisk message formats. The incore message has a pointer
* to the payload. The ondisk message format has payload embedded as
* part of the message.
*
* Caveat Emptor: Incore and ondisk structures have the payload buffers
* correctly allocated.
*/
static void
{
(direction == MD_MN_COPY_TO_INCORE));
if (direction == MD_MN_COPY_TO_ONDISK) {
} else {
}
}
/*
* mdmn_allocate_changelog
*
* Changelog records are allocated on a per multi-node basis.
* This routine is called during MN set creation.
* It pre-allocates the changelog, as user records
* one per message class plus some spares.
* Once the records are allocated they are never freed until
* the mddb is deleted. The preallocation ensures that all nodes
* will have a consistent view of the mddb.
*
* Each record is large enough to hold a maximum sized message
* Return Values:
* 0 - success
* -1 - fail
*/
int
{
int i;
/* Get a pointer to the incore md_set_desc for this MN set */
return (-1);
/*
* Round up the number of changelog records
* to the next value of MDMN_LOGRECS_QUANTA
*
* In all cases, make sure we have at least
* four more entries than the number of classes
* in order to provide space for live upgrades that
* might add classes.
*/
for (i = 0; i < mdmn_logrecs; i++) {
/* grab a record big enough for max message size */
#ifdef DEBUG
#endif
return (-1);
}
}
/* commit class, and selfid */
return (0);
}
/*
* mdmn_reset_changelog
*
* Called during reconfig step 2.
* The only time the changelog is reset is when all nodes in a cluster
* are starting up. In this case changelog must be ignored, therefore
* it is reset.
*
* The function frees the incore data structures and zeros out the
* records. The ondisk records are never freed.
*
* Return Values:
* 0 - success
* -1 - fail
*/
int
{
int lrc;
/* Get a pointer to the incore md_set_desc this MN set */
return (-1);
return (0);
}
if (flag & MDMN_CLF_RESETLOG) {
}
#ifdef DEBUG
#endif
}
/* now zap the array */
if (flag & MDMN_CLF_RESETCACHE) {
#ifdef DEBUG
#endif
mdmn_changelog_snarfed[setno] = 0;
}
return (0);
}
/*
* Log a given message in the changelog.
* This function is only executed by the master node
* Return Values:
* MDMNE_NULL:
* success, the log slot is free
*
* MDMNE_ACK:
* success,
* the log slot is occupied with the same msg from a previous try.
*
* MDMNE_CLASS_BUSY:
* This means the appropriate slot is occupied with a different
* message. In that case the stored message needs being replayed,
* while the current message will be rejected with MDMNE_CLASS_BUSY
* to the initiator.
*
* MDMNE_LOG_FAIL:
* Bad things happend, cannot continue.
*/
int
{
int retval = 0;
/* if not snarfed, snarf it */
"log_msg: No records snarfed\n"));
return (-1);
}
/* log entry for the class */
/* Check if the class is occupied */
"log_msg: id mismatch:\n"
" stored : ID = (%d, 0x%llx-%d)"
" setno %d class %d type %d\n"
" msg to log: ID = (%d, 0x%llx-%d)"
" setno %d class %d type %d.\n"),
return (MDMNE_CLASS_BUSY);
} else {
"log_msg: msgid already logged:\n ID = "
" (%d, 0x%llx-%d) setno %d class %d type %d\n"),
return (MDMNE_ACK);
}
}
if (msg->msg_event_size)
if (retval != 0) {
"mdmn_log_msg - failure committing logged msg to disk\n"));
return (MDMNE_LOG_FAIL);
}
return (MDMNE_NULL); /* this is good */
}
/*
* mdmn_unlog_msg(md_mn_msg_t *)
*
* Clear the log entry holding the indicated message.
* Only the set master can do this.
*
* Return Values:
* 0 - success
* -1 - fail
*/
int
{
int retval = 0;
/* Find the log entry holding the indicated message */
return (-1);
/* assert the message is still logged */
"unlog_msg: msgid mismatch\n"
"\t\tstored: ID = (%d, 0x%llx-%d) setno %d "
"class %d type %d\n"
"\t\tattempting to unlog:\n"
"\t\tID = (%d, 0x%llx-%d) setno %d class %d type %d.\n"),
return (-1);
}
}
/* commit the updated log record to disk */
#ifdef DEBUG
#endif
return (retval);
}
/*
* mdmn_get_changelogrec(set_t , md_mn_msgclass_t)
* Returns a pointer to incore changelog record.
*
* Return Values:
* non-NULL - success
* NULL - fail
*/
{
return (NULL);
}
/*
* mdmn_commitlog(md_set_desc *, md_error_t *)
*
* Commit the set record and all of the changelog entry records to disk.
* Don't bother with other stuff hanging off the set record
* (e.g. drive records) since none of that is changing.
* Called only at changelog pre-allocation time or when flushing a log.
*
* Return Values:
* 0 - success
* errno - fail
*/
static int
{
int lrc;
int *recs;
int retval = 0;
/* Check for master and bounce non-master requests */
if (!(MD_MNSET_DESC(sd))) {
"mdmn_commitlog - Not MN Set\n"));
} else {
"mdmn_commit_log - Not Master\n"));
}
return (-1);
}
/* create the records to commit the info to the mddb */
/* Initialize the log entry records for update */
NULL)) != 0) {
#ifdef DEBUG
"mdmn_commitlog - metaioctl SETDATA failure\n%s",
#endif
break;
}
}
if (retval == 0) {
/* set last rec to be 0 to indicate completion */
/* Commit to mddb on disk */
#ifdef DEBUG
"mdmn_commitlog - metaioctl COMMIT_MANY"
#endif
}
}
return (retval);
}
/*
* mdmn_log_it(set_t, md_error_t *, mdmn_changelog_record_t *)
*
* Commit the changed log record to disk.
*
* Return Values:
* 0 - success
* -1 - fail
*/
static int
{
int *recs;
/* Initialize the log entry record for update */
#ifdef DEBUG
#endif
return (-1);
}
/* Set up the recid to be updated */
recs[1] = 0;
/* Commit to mddb on disk */
#ifdef DEBUG
#endif
return (-1);
}
return (0);
}
/*
* mdmn_snarf_changelog(set_t, md_error_t *)
*
* snarf in the changelog entries and allocate incore structures
* if required.
* mdmn_changelog_snarfed array if set to MDMN_CLF_SNARFED, then
* then the records are already snarfed.
*
* Called from set_snarf(), mdmn_log_msg(), and mdmn_unlog_msg()
* Return Values:
* non-zero - success
* 0 - fail
*/
int
{
if (set == MD_LOCAL_SET)
return (0);
id = 0;
return (mdmn_logrecs);
}
return (0);
/* only allocate if Log records exist */
/* Allocate incore state for the log */
}
do {
/* Since log records counts are fixed return that value */
return (mdmn_logrecs);
}