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

📄 lov_pack.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) 2002, 2003 Cluster File Systems, Inc. *   Author: Andreas Dilger <adilger@clusterfs.com> * *   This file is part of Lustre, http://www.lustre.org. * *   Lustre is free 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. * *   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 *   GNU General Public License for more details. * *   You should have received a copy of the GNU General Public License *   along with Lustre; if not, write to the Free Software *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * (Un)packing of OST/MDS requests * */#define DEBUG_SUBSYSTEM S_LOV#ifndef __KERNEL__#include <liblustre.h>#endif#include <lustre_net.h>#include <obd.h>#include <obd_lov.h>#include <obd_class.h>#include <obd_support.h>#include <lustre/lustre_user.h>#include "lov_internal.h"void lov_dump_lmm_v1(int level, struct lov_mds_md_v1 *lmm){        struct lov_ost_data_v1 *lod;        int i;        CDEBUG(level, "objid "LPX64", magic 0x%08x, pattern %#x\n",               le64_to_cpu(lmm->lmm_object_id), le32_to_cpu(lmm->lmm_magic),               le32_to_cpu(lmm->lmm_pattern));        CDEBUG(level,"stripe_size %u, stripe_count %u\n",               le32_to_cpu(lmm->lmm_stripe_size),               le32_to_cpu(lmm->lmm_stripe_count));        if (le32_to_cpu(lmm->lmm_stripe_count) <= LOV_V1_INSANE_STRIPE_COUNT) {                for (i = 0, lod = lmm->lmm_objects;                     i < (int)le32_to_cpu(lmm->lmm_stripe_count); i++, lod++)                         CDEBUG(level,                                "stripe %u idx %u subobj "LPX64"/"LPX64"\n",                                i, le32_to_cpu(lod->l_ost_idx),                                le64_to_cpu(lod->l_object_gr),                                le64_to_cpu(lod->l_object_id));        } else {                CDEBUG(level, "bad stripe_count %u > max_stripe_count %u\n",                       le32_to_cpu(lmm->lmm_stripe_count),                       LOV_V1_INSANE_STRIPE_COUNT);        }}void lov_dump_lmm_join(int level, struct lov_mds_md_join *lmmj){        CDEBUG(level, "objid "LPX64", magic 0x%08X, pattern %#X\n",               le64_to_cpu(lmmj->lmmj_md.lmm_object_id),                le32_to_cpu(lmmj->lmmj_md.lmm_magic),               le32_to_cpu(lmmj->lmmj_md.lmm_pattern));        CDEBUG(level,"stripe_size %u, stripe_count %u extent_count %u \n",               le32_to_cpu(lmmj->lmmj_md.lmm_stripe_size),               le32_to_cpu(lmmj->lmmj_md.lmm_stripe_count),                le32_to_cpu(lmmj->lmmj_extent_count));}#define LMM_ASSERT(test)                                                \do {                                                                    \        if (!(test)) lov_dump_lmm(D_ERROR, lmm);                        \        LASSERT(test); /* so we know what assertion failed */           \} while(0)/* Pack LOV object metadata for disk storage.  It is packed in LE byte * order and is opaque to the networking layer. * * XXX In the future, this will be enhanced to get the EA size from the *     underlying OSC device(s) to get their EA sizes so we can stack *     LOVs properly.  For now lov_mds_md_size() just assumes one obd_id *     per stripe. */int lov_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,               struct lov_stripe_md *lsm){        struct obd_device *obd = class_exp2obd(exp);        struct lov_obd *lov = &obd->u.lov;        struct lov_oinfo *loi;        struct lov_mds_md *lmm;        int stripe_count = lov->desc.ld_tgt_count;        int lmm_size;        int i;        ENTRY;        if (lsm) {                if (lsm->lsm_magic != LOV_MAGIC) {                        CERROR("bad mem LOV MAGIC: 0x%08X != 0x%08X\n",                               lsm->lsm_magic, LOV_MAGIC);                        RETURN(-EINVAL);                }                if (!lmmp) {                        stripe_count = lov_get_stripecnt(lov, lsm->lsm_stripe_count);                        lsm->lsm_stripe_count = stripe_count;                } else {                        stripe_count = lsm->lsm_stripe_count;                }        }        /* XXX LOV STACKING call into osc for sizes */        lmm_size = lov_mds_md_size(stripe_count);        if (!lmmp)                RETURN(lmm_size);        if (*lmmp && !lsm) {                stripe_count = le32_to_cpu((*lmmp)->lmm_stripe_count);                OBD_FREE(*lmmp, lov_mds_md_size(stripe_count));                *lmmp = NULL;                RETURN(0);        }        if (!*lmmp) {                OBD_ALLOC(*lmmp, lmm_size);                if (!*lmmp)                        RETURN(-ENOMEM);        }        lmm = *lmmp;        lmm->lmm_magic = cpu_to_le32(LOV_MAGIC); /* only write new format */        if (!lsm)                RETURN(lmm_size);        lmm->lmm_object_id = cpu_to_le64(lsm->lsm_object_id);        lmm->lmm_object_gr = cpu_to_le64(lsm->lsm_object_gr);        lmm->lmm_stripe_size = cpu_to_le32(lsm->lsm_stripe_size);        lmm->lmm_stripe_count = cpu_to_le32(stripe_count);        lmm->lmm_pattern = cpu_to_le32(lsm->lsm_pattern);        for (i = 0; i < stripe_count; i++) {                loi = lsm->lsm_oinfo[i];                /* XXX LOV STACKING call down to osc_packmd() to do packing */                LASSERTF(loi->loi_id, "lmm_oid "LPU64" stripe %u/%u idx %u\n",                         lmm->lmm_object_id, i, stripe_count, loi->loi_ost_idx);                lmm->lmm_objects[i].l_object_id = cpu_to_le64(loi->loi_id);                lmm->lmm_objects[i].l_object_gr = cpu_to_le64(loi->loi_gr);                lmm->lmm_objects[i].l_ost_gen = cpu_to_le32(loi->loi_ost_gen);                lmm->lmm_objects[i].l_ost_idx = cpu_to_le32(loi->loi_ost_idx);        }        RETURN(lmm_size);}/* Find the max stripecount we should use */int lov_get_stripecnt(struct lov_obd *lov, __u32 stripe_count){        if (!stripe_count)                stripe_count = lov->desc.ld_default_stripe_count;        if (stripe_count > lov->desc.ld_active_tgt_count)                stripe_count = lov->desc.ld_active_tgt_count;        if (!stripe_count)                stripe_count = 1;        /* for now, we limit the stripe count directly, when bug 4424 is         * fixed this needs to be somewhat dynamic based on whether ext3         * can handle larger EA sizes. */        if (stripe_count > LOV_MAX_STRIPE_COUNT)                stripe_count = LOV_MAX_STRIPE_COUNT;        return stripe_count;}static int lov_verify_lmm(void *lmm, int lmm_bytes, int *stripe_count){        int rc;        if (lsm_op_find(le32_to_cpu(*(__u32 *)lmm)) == NULL) {                CERROR("bad disk LOV MAGIC: 0x%08X; dumping V1 LMM:\n",                       le32_to_cpu(*(__u32 *)lmm));                lov_dump_lmm_v1(D_WARNING, lmm);                return -EINVAL;        }        rc = lsm_op_find(le32_to_cpu(*(__u32 *)lmm))->lsm_lmm_verify(lmm,                                     lmm_bytes, stripe_count);        return rc;}int lov_alloc_memmd(struct lov_stripe_md **lsmp, int stripe_count,                       int pattern, int magic){        int i, lsm_size;        ENTRY;        CDEBUG(D_INFO, "alloc lsm, stripe_count %d\n", stripe_count);        *lsmp = lsm_alloc_plain(stripe_count, &lsm_size);        if (!*lsmp) {                CERROR("can't allocate lsmp, stripe_count %d\n", stripe_count);                RETURN(-ENOMEM);        }        spin_lock_init(&(*lsmp)->lsm_lock);        (*lsmp)->lsm_magic = magic;        (*lsmp)->lsm_stripe_count = stripe_count;        (*lsmp)->lsm_maxbytes = LUSTRE_STRIPE_MAXBYTES * stripe_count;        (*lsmp)->lsm_pattern = pattern;        (*lsmp)->lsm_oinfo[0]->loi_ost_idx = ~0;        for (i = 0; i < stripe_count; i++)                loi_init((*lsmp)->lsm_oinfo[i]);        RETURN(lsm_size);}void lov_free_memmd(struct lov_stripe_md **lsmp){        struct lov_stripe_md *lsm = *lsmp;

⌨️ 快捷键说明

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