⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 llog.c

📁 lustre 1.6.5 source code
💻 C
📖 第 1 页 / 共 2 页
字号:
/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * *  Copyright (C) 2001-2003 Cluster File Systems, Inc. *   Author: Andreas Dilger <adilger@clusterfs.com> * *   This file is part of the Lustre file system, http://www.lustre.org *   Lustre is a trademark of Cluster File Systems, Inc. * *   You may have signed or agreed to another license before downloading *   this software.  If so, you are bound by the terms and conditions *   of that agreement, and the following does not apply to you.  See the *   LICENSE file included with this distribution for more information. * *   If you did not agree to a different license, then this copy of Lustre *   is open source software; you can redistribute it and/or modify it *   under the terms of version 2 of the GNU General Public License as *   published by the Free Software Foundation. * *   In either case, Lustre 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 *   license text for more details. * * OST<->MDS recovery logging infrastructure. * * Invariants in implementation: * - we do not share logs among different OST<->MDS connections, so that *   if an OST or MDS fails it need only look at log(s) relevant to itself */#define DEBUG_SUBSYSTEM S_LOG#ifndef EXPORT_SYMTAB#define EXPORT_SYMTAB#endif#ifndef __KERNEL__#include <liblustre.h>#endif#include <obd_class.h>#include <lustre_log.h>#include <libcfs/list.h>/* Allocate a new log or catalog handle */struct llog_handle *llog_alloc_handle(void){        struct llog_handle *loghandle;        ENTRY;        OBD_ALLOC(loghandle, sizeof(*loghandle));        if (loghandle == NULL)                RETURN(ERR_PTR(-ENOMEM));        init_rwsem(&loghandle->lgh_lock);        RETURN(loghandle);}EXPORT_SYMBOL(llog_alloc_handle);void llog_free_handle(struct llog_handle *loghandle){        if (!loghandle)                return;        if (!loghandle->lgh_hdr)                goto out;        if (loghandle->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN)                list_del_init(&loghandle->u.phd.phd_entry);        if (loghandle->lgh_hdr->llh_flags & LLOG_F_IS_CAT)                LASSERT(list_empty(&loghandle->u.chd.chd_head));        OBD_FREE(loghandle->lgh_hdr, LLOG_CHUNK_SIZE); out:        OBD_FREE(loghandle, sizeof(*loghandle));}EXPORT_SYMBOL(llog_free_handle);/* returns negative on error; 0 if success; 1 if success & log destroyed */int llog_cancel_rec(struct llog_handle *loghandle, int index){        struct llog_log_hdr *llh = loghandle->lgh_hdr;        int rc = 0;        ENTRY;        CDEBUG(D_RPCTRACE, "canceling %d in log "LPX64"\n",               index, loghandle->lgh_id.lgl_oid);        if (index == 0) {                CERROR("cannot cancel index 0 (which is header)\n");                RETURN(-EINVAL);        }        if (!ext2_clear_bit(index, llh->llh_bitmap)) {                CDEBUG(D_RPCTRACE, "catalog index %u already clear?\n", index);                RETURN(-EINVAL);        }        llh->llh_count--;        if ((llh->llh_flags & LLOG_F_ZAP_WHEN_EMPTY) &&            (llh->llh_count == 1) &&            (loghandle->lgh_last_idx == (LLOG_BITMAP_BYTES * 8) - 1)) {                rc = llog_destroy(loghandle);                if (rc) {                        CERROR("failure destroying log after last cancel: %d\n",                               rc);                        ext2_set_bit(index, llh->llh_bitmap);                        llh->llh_count++;                } else {                        rc = 1;                }                RETURN(rc);        }        rc = llog_write_rec(loghandle, &llh->llh_hdr, NULL, 0, NULL, 0);        if (rc) {                CERROR("failure re-writing header %d\n", rc);                ext2_set_bit(index, llh->llh_bitmap);                llh->llh_count++;        }        RETURN(rc);}EXPORT_SYMBOL(llog_cancel_rec);int llog_init_handle(struct llog_handle *handle, int flags,                     struct obd_uuid *uuid){        int rc;        struct llog_log_hdr *llh;        ENTRY;        LASSERT(handle->lgh_hdr == NULL);        OBD_ALLOC(llh, sizeof(*llh));        if (llh == NULL)                RETURN(-ENOMEM);        handle->lgh_hdr = llh;        /* first assign flags to use llog_client_ops */        llh->llh_flags = flags;        rc = llog_read_header(handle);        if (rc == 0) {                flags = llh->llh_flags;                if (uuid && !obd_uuid_equals(uuid, &llh->llh_tgtuuid)) {                        CERROR("uuid mismatch: %s/%s\n", (char *)uuid->uuid,                               (char *)llh->llh_tgtuuid.uuid);                        rc = -EEXIST;                }                GOTO(out, rc);        } else if (rc != LLOG_EEMPTY || !flags) {                /* set a pesudo flag for initialization */                flags = LLOG_F_IS_CAT;                GOTO(out, rc);        }        rc = 0;        handle->lgh_last_idx = 0; /* header is record with index 0 */        llh->llh_count = 1;         /* for the header record */        llh->llh_hdr.lrh_type = LLOG_HDR_MAGIC;        llh->llh_hdr.lrh_len = llh->llh_tail.lrt_len = LLOG_CHUNK_SIZE;        llh->llh_hdr.lrh_index = llh->llh_tail.lrt_index = 0;        llh->llh_timestamp = CURRENT_SECONDS;        if (uuid)                memcpy(&llh->llh_tgtuuid, uuid, sizeof(llh->llh_tgtuuid));        llh->llh_bitmap_offset = offsetof(typeof(*llh),llh_bitmap);        ext2_set_bit(0, llh->llh_bitmap);out:        if (flags & LLOG_F_IS_CAT) {                CFS_INIT_LIST_HEAD(&handle->u.chd.chd_head);                llh->llh_size = sizeof(struct llog_logid_rec);        } else if (flags & LLOG_F_IS_PLAIN) {                CFS_INIT_LIST_HEAD(&handle->u.phd.phd_entry);        } else {                CERROR("Unknown flags: %#x (Expected %#x or %#x\n",                       flags, LLOG_F_IS_CAT, LLOG_F_IS_PLAIN);                LBUG();        }        if (rc) {                OBD_FREE(llh, sizeof(*llh));                handle->lgh_hdr = NULL;        }        RETURN(rc);}EXPORT_SYMBOL(llog_init_handle);int llog_close(struct llog_handle *loghandle){        struct llog_operations *lop;        int rc;        ENTRY;        rc = llog_handle2ops(loghandle, &lop);        if (rc)                GOTO(out, rc);        if (lop->lop_close == NULL)                GOTO(out, -EOPNOTSUPP);        rc = lop->lop_close(loghandle); out:        llog_free_handle(loghandle);        RETURN(rc);}EXPORT_SYMBOL(llog_close);int llog_process(struct llog_handle *loghandle, llog_cb_t cb,                 void *data, void *catdata){        struct llog_log_hdr *llh = loghandle->lgh_hdr;        struct llog_process_cat_data *cd = catdata;        char *buf;        __u64 cur_offset = LLOG_CHUNK_SIZE, last_offset;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -