llog_ioctl.c
来自「lustre 1.6.5 source code」· C语言 代码 · 共 453 行 · 第 1/2 页
C
453 行
/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * * Copyright (C) 2005 Cluster File Systems, Inc. * * 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. */#define DEBUG_SUBSYSTEM S_LOG#ifndef EXPORT_SYMTAB#define EXPORT_SYMTAB#endif#include <obd_class.h>#include <lustre_log.h>#include <libcfs/list.h>#include "llog_internal.h"static int str2logid(struct llog_logid *logid, char *str, int len){ char *start, *end, *endp; ENTRY; start = str; if (*start != '#') RETURN(-EINVAL); start++; if (start - str >= len - 1) RETURN(-EINVAL); end = strchr(start, '#'); if (end == NULL || end == start) RETURN(-EINVAL); *end = '\0'; logid->lgl_oid = simple_strtoull(start, &endp, 0); if (endp != end) RETURN(-EINVAL); start = ++end; if (start - str >= len - 1) RETURN(-EINVAL); end = strchr(start, '#'); if (end == NULL || end == start) RETURN(-EINVAL); *end = '\0'; logid->lgl_ogr = simple_strtoull(start, &endp, 0); if (endp != end) RETURN(-EINVAL); start = ++end; if (start - str >= len - 1) RETURN(-EINVAL); logid->lgl_ogen = simple_strtoul(start, &endp, 16); if (*endp != '\0') RETURN(-EINVAL); RETURN(0);}static int llog_check_cb(struct llog_handle *handle, struct llog_rec_hdr *rec, void *data){ struct obd_ioctl_data *ioc_data = (struct obd_ioctl_data *)data; static int l, remains, from, to; static char *out; char *endp; int cur_index, rc = 0; ENTRY; cur_index = rec->lrh_index; if (ioc_data && (ioc_data->ioc_inllen1)) { l = 0; remains = ioc_data->ioc_inllen4 + size_round(ioc_data->ioc_inllen1) + size_round(ioc_data->ioc_inllen2) + size_round(ioc_data->ioc_inllen3); from = simple_strtol(ioc_data->ioc_inlbuf2, &endp, 0); if (*endp != '\0') RETURN(-EINVAL); to = simple_strtol(ioc_data->ioc_inlbuf3, &endp, 0); if (*endp != '\0') RETURN(-EINVAL); ioc_data->ioc_inllen1 = 0; out = ioc_data->ioc_bulk; if (cur_index < from) RETURN(0); if (to > 0 && cur_index > to) RETURN(-LLOG_EEMPTY); } if (handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT) { struct llog_logid_rec *lir = (struct llog_logid_rec *)rec; struct llog_handle *log_handle; if (rec->lrh_type != LLOG_LOGID_MAGIC) { l = snprintf(out, remains, "[index]: %05d [type]: " "%02x [len]: %04d failed\n", cur_index, rec->lrh_type, rec->lrh_len); } if (handle->lgh_ctxt == NULL) RETURN(-EOPNOTSUPP); rc = llog_cat_id2handle(handle, &log_handle, &lir->lid_id); if (rc) { CDEBUG(D_IOCTL, "cannot find log #"LPX64"#"LPX64"#%08x\n", lir->lid_id.lgl_oid, lir->lid_id.lgl_ogr, lir->lid_id.lgl_ogen); RETURN(rc); } rc = llog_process(log_handle, llog_check_cb, NULL, NULL); llog_close(log_handle); } else { switch (rec->lrh_type) { case OST_SZ_REC: case OST_RAID1_REC: case MDS_UNLINK_REC: case MDS_SETATTR_REC: case OBD_CFG_REC: case LLOG_HDR_MAGIC: { l = snprintf(out, remains, "[index]: %05d [type]: " "%02x [len]: %04d ok\n", cur_index, rec->lrh_type, rec->lrh_len); out += l; remains -= l; if (remains <= 0) { CERROR("no space to print log records\n"); RETURN(-LLOG_EEMPTY); } RETURN(0); } default: { l = snprintf(out, remains, "[index]: %05d [type]: " "%02x [len]: %04d failed\n", cur_index, rec->lrh_type, rec->lrh_len); out += l; remains -= l; if (remains <= 0) { CERROR("no space to print log records\n"); RETURN(-LLOG_EEMPTY); } RETURN(0); } } } RETURN(rc);}static int llog_print_cb(struct llog_handle *handle, struct llog_rec_hdr *rec, void *data){ struct obd_ioctl_data *ioc_data = (struct obd_ioctl_data *)data; static int l, remains, from, to; static char *out; char *endp; int cur_index; ENTRY; if (ioc_data->ioc_inllen1) { l = 0; remains = ioc_data->ioc_inllen4 + size_round(ioc_data->ioc_inllen1) + size_round(ioc_data->ioc_inllen2) + size_round(ioc_data->ioc_inllen3); from = simple_strtol(ioc_data->ioc_inlbuf2, &endp, 0); if (*endp != '\0') RETURN(-EINVAL); to = simple_strtol(ioc_data->ioc_inlbuf3, &endp, 0); if (*endp != '\0') RETURN(-EINVAL); out = ioc_data->ioc_bulk; ioc_data->ioc_inllen1 = 0; } cur_index = rec->lrh_index; if (cur_index < from) RETURN(0); if (to > 0 && cur_index > to) RETURN(-LLOG_EEMPTY); if (handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT) { struct llog_logid_rec *lir = (struct llog_logid_rec *)rec; if (rec->lrh_type != LLOG_LOGID_MAGIC) { CERROR("invalid record in catalog\n"); RETURN(-EINVAL); } l = snprintf(out, remains, "[index]: %05d [logid]: #"LPX64"#"LPX64"#%08x\n", cur_index, lir->lid_id.lgl_oid, lir->lid_id.lgl_ogr, lir->lid_id.lgl_ogen); } else { l = snprintf(out, remains, "[index]: %05d [type]: %02x [len]: %04d\n", cur_index, rec->lrh_type, rec->lrh_len); } out += l; remains -= l; if (remains <= 0) { CERROR("not enough space for print log records\n"); RETURN(-LLOG_EEMPTY); } RETURN(0);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?