1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 # define EXPORT_SYMTAB
25 #define DEBUG_SUBSYSTEM S_LOV
28 #include <asm/div64.h>
30 #include <liblustre.h>
33 #include <linux/obd_class.h>
34 #include <linux/obd_lov.h>
36 #include "lov_internal.h"
38 /* Merge rss if kms == 0
40 * Even when merging RSS, we will take the KMS value if it's larger.
41 * This prevents getattr from stomping on dirty cached pages which
42 * extend the file size. */
43 __u64 lov_merge_size(struct lov_stripe_md *lsm, int kms)
45 struct lov_oinfo *loi;
49 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
51 obd_size lov_size, tmpsize;
53 tmpsize = loi->loi_kms;
54 if (kms == 0 && loi->loi_rss > tmpsize)
55 tmpsize = loi->loi_rss;
57 lov_size = lov_stripe_size(lsm, tmpsize, i);
64 EXPORT_SYMBOL(lov_merge_size);
67 __u64 lov_merge_blocks(struct lov_stripe_md *lsm)
69 struct lov_oinfo *loi;
73 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++, loi++)
74 blocks += loi->loi_blocks;
77 EXPORT_SYMBOL(lov_merge_blocks);
79 __u64 lov_merge_mtime(struct lov_stripe_md *lsm, __u64 current_time)
81 struct lov_oinfo *loi;
84 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++, loi++)
85 if (loi->loi_mtime > current_time)
86 current_time = loi->loi_mtime;
89 EXPORT_SYMBOL(lov_merge_mtime);
91 int lov_adjust_kms(struct obd_export *exp, struct lov_stripe_md *lsm,
92 obd_off size, int shrink)
94 struct lov_oinfo *loi;
100 struct lov_oinfo *loi;
102 for (loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
104 kms = lov_size_to_stripe(lsm, size, i);
105 loi->loi_kms = loi->loi_rss = kms;
111 stripe = lov_stripe_number(lsm, size - 1);
112 kms = lov_size_to_stripe(lsm, size, stripe);
113 loi = &(lsm->lsm_oinfo[stripe]);
115 CDEBUG(D_INODE, "stripe %d KMS %sincreasing "LPU64"->"LPU64"\n",
116 stripe, kms > loi->loi_kms ? "" : "not ", loi->loi_kms, kms);
117 if (kms > loi->loi_kms)
122 EXPORT_SYMBOL(lov_adjust_kms);
124 void lov_merge_attrs(struct obdo *tgt, struct obdo *src, obd_flags valid,
125 struct lov_stripe_md *lsm, int stripeno, int *set)
127 valid &= src->o_valid;
130 if (valid & OBD_MD_FLSIZE) {
131 /* this handles sparse files properly */
134 lov_size = lov_stripe_size(lsm, src->o_size, stripeno);
135 if (lov_size > tgt->o_size)
136 tgt->o_size = lov_size;
138 if (valid & OBD_MD_FLBLOCKS)
139 tgt->o_blocks += src->o_blocks;
140 if (valid & OBD_MD_FLBLKSZ)
141 tgt->o_blksize += src->o_blksize;
142 if (valid & OBD_MD_FLCTIME && tgt->o_ctime < src->o_ctime)
143 tgt->o_ctime = src->o_ctime;
144 if (valid & OBD_MD_FLMTIME && tgt->o_mtime < src->o_mtime)
145 tgt->o_mtime = src->o_mtime;
147 memcpy(tgt, src, sizeof(*tgt));
148 tgt->o_id = lsm->lsm_object_id;
149 if (valid & OBD_MD_FLSIZE)
150 tgt->o_size = lov_stripe_size(lsm,src->o_size,stripeno);