1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
/*
*
* (C) Copyright IBM Corp. 2001, 2003
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Module: libcsm.so
*
* File: commit.c
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <plugin.h>
#include "csm_plugin.h"
/*
* Function: write_metadata
*
* Called with a CSM metadata storage object to commit to disk. A CSM metadata
* storage object holds a ptr in its private data to a CSM header that will be
* committed to disk. The size and location of the CSM header on disk? It is
* always equal to the size and location of the metadata storage object!
*/
int write_metadata( DISKSEG *md, LOGICALDISK *ld,
DISKSEG *seg, boolean backup )
{
int rc=0;
csm_header_t *hdr=NULL;
u_int32_t crc;
u_int32_t size = 0;
LOG_ENTRY();
LOG_DEBUG("writing metadata on object %s\n", ld->name);
hdr = (void *) calloc(1, (EVMS_VSECTOR_SIZE*md->size) );
if (hdr) {
memcpy( hdr,
((seg_private_data_t *)md->private_data)->hdr,
((seg_private_data_t *)md->private_data)->hdr->size );
size = hdr->size;
cpu_csm_header_to_disk( hdr );
hdr->crc = 0;
crc = EngFncs->calculate_CRC( EVMS_INITIAL_CRC,hdr,size );
hdr->crc = CPU_TO_DISK32(~crc);
if (backup) {
rc = EngFncs->save_metadata( seg->name, ld->name,
md->start, md->size, hdr );
} else {
rc = WRITE( ld, md->start, md->size, (void *) hdr );
}
if (rc) {
LOG_ERROR("ERROR--> WRITE METADATA TO LBA %"PRIu64" FAILED WITH RC= %d\n", md->start,rc);
}
free(hdr);
}
else {
rc = ENOMEM;
}
LOG_EXIT_INT(rc);
return rc;
}
/*
* Function: commit_csm_metadata
*
* Called by the CSM plug-in commit api with:
*
* (1) a dirty segment storage object
* (2) the logical disk the segment is found on
* (3) the current commit phase
*
* A CSM commit follows this logic:
*
* IF ... dirty_segment == a CSM metadata segment
* THEN ... IF metadata segments commit phase matches current commit phase
* THEN commit the metdata segment and mark it clean
* ELSE leave the metadata segment dirty for subsequent commit phases
* ELSE ... simply mark the storage object clean
*
* The result is that the all 3 CSM segments will be committed at an
* appropriate time. The data segment ... whenever it first appears. The
* 1st metadata segment during phase 1. The 2nd metadata segment during
* phase 2.
*/
int commit_csm_metadata( DISKSEG *seg, LOGICALDISK *ld, uint commit_phase )
{
int rc=0;
seg_private_data_t *pdata;
LOG_ENTRY();
REQUIRE(ld != NULL);
REQUIRE(seg != NULL);
pdata = (seg_private_data_t *) seg->private_data;
REQUIRE(pdata != NULL);
if ( seg->data_type == META_DATA_TYPE ) {
if ( pdata->commit_phase == commit_phase ) {
rc = write_metadata( seg, ld, NULL, FALSE );
if (!rc) {
seg->flags &= ~SOFLAG_DIRTY;
}
}
}
else {
seg->flags &= ~SOFLAG_DIRTY;
}
LOG_EXIT_INT(rc);
return rc;
}
|