llog_server.c

来自「lustre 1.6.5 source code」· C语言 代码 · 共 717 行 · 第 1/2 页

C
717
字号
/* -*- 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. * *  remote api for llog - server side * */#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 <lustre_net.h>#include <libcfs/list.h>#include <lustre_fsfilt.h>#if defined(__KERNEL__) && defined(LUSTRE_LOG_SERVER)int llog_origin_handle_create(struct ptlrpc_request *req){        struct obd_export *exp = req->rq_export;        struct obd_device *obd = exp->exp_obd;        struct obd_device *disk_obd;        struct llog_handle  *loghandle;        struct llogd_body *body;        struct lvfs_run_ctxt saved;        struct llog_logid *logid = NULL;        struct llog_ctxt *ctxt;        char * name = NULL;        int size[2] = { sizeof(struct ptlrpc_body), sizeof(*body) };        int rc, rc2;        ENTRY;        body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),                                 lustre_swab_llogd_body);        if (body == NULL) {                CERROR ("Can't unpack llogd_body\n");                RETURN(-EFAULT);        }        if (body->lgd_logid.lgl_oid > 0)                logid = &body->lgd_logid;        if (lustre_msg_bufcount(req->rq_reqmsg) > 2) {                name = lustre_msg_string(req->rq_reqmsg, REQ_REC_OFF + 1, 0);                if (name == NULL) {                        CERROR("Can't unpack name\n");                        RETURN(-EFAULT);                }                CDEBUG(D_INFO, "opening log %s\n", name);        }        ctxt = llog_get_context(obd, body->lgd_ctxt_idx);        if (ctxt == NULL)                RETURN(-EINVAL);        disk_obd = ctxt->loc_exp->exp_obd;        push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);        rc = llog_create(ctxt, &loghandle, logid, name);        if (rc)                GOTO(out_pop, rc);        rc = lustre_pack_reply(req, 2, size, NULL);        if (rc)                GOTO(out_close, rc = -ENOMEM);        body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*body));        body->lgd_logid = loghandle->lgh_id;out_close:        rc2 = llog_close(loghandle);        if (!rc)                rc = rc2;out_pop:        pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);        llog_ctxt_put(ctxt);        RETURN(rc);}int llog_origin_handle_destroy(struct ptlrpc_request *req){        struct obd_export *exp = req->rq_export;        struct obd_device *obd = exp->exp_obd;        struct obd_device *disk_obd;        struct llog_handle  *loghandle;        struct llogd_body *body;        struct lvfs_run_ctxt saved;        struct llog_logid *logid = NULL;        struct llog_ctxt *ctxt;        int size[] = { sizeof(struct ptlrpc_body), sizeof(*body) };        int rc;        __u32 flags;        ENTRY;        body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),                                 lustre_swab_llogd_body);        if (body == NULL) {                CERROR ("Can't unpack llogd_body\n");                RETURN(-EFAULT);        }        if (body->lgd_logid.lgl_oid > 0)                logid = &body->lgd_logid;        ctxt = llog_get_context(obd, body->lgd_ctxt_idx);        if (ctxt == NULL)                RETURN(-EINVAL);        disk_obd = ctxt->loc_exp->exp_obd;        push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);        rc = llog_create(ctxt, &loghandle, logid, NULL);        if (rc)                GOTO(out_pop, rc);        rc = lustre_pack_reply(req, 2, size, NULL);        if (rc)                GOTO(out_close, rc = -ENOMEM);        body = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof (*body));        body->lgd_logid = loghandle->lgh_id;        flags = body->lgd_llh_flags;        rc = llog_init_handle(loghandle, LLOG_F_IS_PLAIN, NULL);        if (rc)                GOTO(out_close, rc);        rc = llog_destroy(loghandle);        if (rc)                GOTO(out_close, rc);        llog_free_handle(loghandle);out_close:        if (rc)                llog_close(loghandle);out_pop:        pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);        llog_ctxt_put(ctxt);        RETURN(rc);}int llog_origin_handle_next_block(struct ptlrpc_request *req){        struct obd_export *exp = req->rq_export;        struct obd_device *obd = exp->exp_obd;        struct obd_device *disk_obd;        struct llog_handle  *loghandle;        struct llogd_body *body;        struct lvfs_run_ctxt saved;        struct llog_ctxt *ctxt;        __u32 flags;        __u8 *buf;        void * ptr;        int size[3] = { sizeof(struct ptlrpc_body),                        sizeof(*body),                        LLOG_CHUNK_SIZE };        int rc, rc2;        ENTRY;        body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),                                  lustre_swab_llogd_body);        if (body == NULL) {                CERROR ("Can't unpack llogd_body\n");                RETURN(-EFAULT);        }        OBD_ALLOC(buf, LLOG_CHUNK_SIZE);        if (!buf)                RETURN(-ENOMEM);        ctxt = llog_get_context(obd, body->lgd_ctxt_idx);        if (ctxt == NULL)                GOTO(out_free, rc = -EINVAL);        disk_obd = ctxt->loc_exp->exp_obd;        push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);        rc = llog_create(ctxt, &loghandle, &body->lgd_logid, NULL);        if (rc)                GOTO(out_pop, rc);        flags = body->lgd_llh_flags;        rc = llog_init_handle(loghandle, flags, NULL);        if (rc)                GOTO(out_close, rc);        memset(buf, 0, LLOG_CHUNK_SIZE);        rc = llog_next_block(loghandle, &body->lgd_saved_index,                             body->lgd_index,                             &body->lgd_cur_offset, buf, LLOG_CHUNK_SIZE);        if (rc)                GOTO(out_close, rc);        rc = lustre_pack_reply(req, 3, size, NULL);        if (rc)                GOTO(out_close, rc = -ENOMEM);        ptr = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof (body));        memcpy(ptr, body, sizeof(*body));        ptr = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF+1, LLOG_CHUNK_SIZE);        memcpy(ptr, buf, LLOG_CHUNK_SIZE);out_close:        rc2 = llog_close(loghandle);        if (!rc)                rc = rc2;out_pop:        pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);        llog_ctxt_put(ctxt);out_free:        OBD_FREE(buf, LLOG_CHUNK_SIZE);        RETURN(rc);}int llog_origin_handle_prev_block(struct ptlrpc_request *req){        struct obd_export *exp = req->rq_export;        struct obd_device *obd = exp->exp_obd;        struct llog_handle  *loghandle;        struct llogd_body *body;        struct obd_device *disk_obd;        struct lvfs_run_ctxt saved;        struct llog_ctxt *ctxt;        __u32 flags;        __u8 *buf;        void * ptr;        int size[] = { sizeof(struct ptlrpc_body),                       sizeof(*body),                       LLOG_CHUNK_SIZE };        int rc, rc2;        ENTRY;        body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),                                  lustre_swab_llogd_body);        if (body == NULL) {                CERROR ("Can't unpack llogd_body\n");                RETURN(-EFAULT);        }        OBD_ALLOC(buf, LLOG_CHUNK_SIZE);        if (!buf)                RETURN(-ENOMEM);        ctxt = llog_get_context(obd, body->lgd_ctxt_idx);        LASSERT(ctxt != NULL);        disk_obd = ctxt->loc_exp->exp_obd;        push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);        rc = llog_create(ctxt, &loghandle, &body->lgd_logid, NULL);        if (rc)                GOTO(out_pop, rc);        flags = body->lgd_llh_flags;        rc = llog_init_handle(loghandle, flags, NULL);        if (rc)                GOTO(out_close, rc);        memset(buf, 0, LLOG_CHUNK_SIZE);        rc = llog_prev_block(loghandle, body->lgd_index,                             buf, LLOG_CHUNK_SIZE);        if (rc)                GOTO(out_close, rc);        rc = lustre_pack_reply(req, 3, size, NULL);        if (rc)                GOTO(out_close, rc = -ENOMEM);        ptr = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(body));        memcpy(ptr, body, sizeof(*body));        ptr = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF+1, LLOG_CHUNK_SIZE);        memcpy(ptr, buf, LLOG_CHUNK_SIZE);out_close:        rc2 = llog_close(loghandle);        if (!rc)                rc = rc2;out_pop:        pop_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);        llog_ctxt_put(ctxt);        OBD_FREE(buf, LLOG_CHUNK_SIZE);        RETURN(rc);}int llog_origin_handle_read_header(struct ptlrpc_request *req){        struct obd_export *exp = req->rq_export;        struct obd_device *obd = exp->exp_obd;        struct obd_device *disk_obd;        struct llog_handle  *loghandle;        struct llogd_body *body;        struct llog_log_hdr *hdr;        struct lvfs_run_ctxt saved;        struct llog_ctxt *ctxt;        __u32 flags;        int size[2] = { sizeof(struct ptlrpc_body), sizeof(*hdr) };        int rc, rc2;        ENTRY;        body = lustre_swab_reqbuf(req, REQ_REC_OFF, sizeof(*body),                                  lustre_swab_llogd_body);        if (body == NULL) {                CERROR ("Can't unpack llogd_body\n");                RETURN(-EFAULT);        }        ctxt = llog_get_context(obd, body->lgd_ctxt_idx);        if (ctxt == NULL)                RETURN(-EINVAL);        disk_obd = ctxt->loc_exp->exp_obd;        push_ctxt(&saved, &disk_obd->obd_lvfs_ctxt, NULL);        rc = llog_create(ctxt, &loghandle, &body->lgd_logid, NULL);        if (rc)                GOTO(out_pop, rc);        /* init_handle reads the header */        flags = body->lgd_llh_flags;        rc = llog_init_handle(loghandle, flags, NULL);        if (rc)                GOTO(out_close, rc);        rc = lustre_pack_reply(req, 2, size, NULL);        if (rc)                GOTO(out_close, rc = -ENOMEM);        hdr = lustre_msg_buf(req->rq_repmsg, REPLY_REC_OFF, sizeof(*hdr));        memcpy(hdr, loghandle->lgh_hdr, sizeof(*hdr));out_close:

⌨️ 快捷键说明

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