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 the Lustre file system, http://www.lustre.org
7 * Lustre is a trademark of Cluster File Systems, Inc.
9 * You may have signed or agreed to another license before downloading
10 * this software. If so, you are bound by the terms and conditions
11 * of that agreement, and the following does not apply to you. See the
12 * LICENSE file included with this distribution for more information.
14 * If you did not agree to a different license, then this copy of Lustre
15 * is open source software; you can redistribute it and/or modify it
16 * under the terms of version 2 of the GNU General Public License as
17 * published by the Free Software Foundation.
19 * In either case, Lustre is distributed in the hope that it will be
20 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
21 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * license text for more details.
26 # define EXPORT_SYMTAB
28 #define DEBUG_SUBSYSTEM S_LOV
31 #include <asm/div64.h>
33 #include <liblustre.h>
36 #include <linux/obd_class.h>
37 #include <linux/obd_lov.h>
39 #include "lov_internal.h"
41 /* Merge rss if kms == 0
43 * Even when merging RSS, we will take the KMS value if it's larger.
44 * This prevents getattr from stomping on dirty cached pages which
45 * extend the file size. */
46 __u64 lov_merge_size(struct lov_stripe_md *lsm, int kms)
48 struct lov_oinfo *loi;
52 LASSERT_SPIN_LOCKED(&lsm->lsm_lock);
54 LASSERT(lsm->lsm_lock_owner == current);
57 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count;
59 obd_size lov_size, tmpsize;
61 tmpsize = loi->loi_kms;
62 if (kms == 0 && loi->loi_rss > tmpsize)
63 tmpsize = loi->loi_rss;
65 lov_size = lov_stripe_size(lsm, tmpsize, i);
72 EXPORT_SYMBOL(lov_merge_size);
75 __u64 lov_merge_blocks(struct lov_stripe_md *lsm)
77 struct lov_oinfo *loi;
81 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++, loi++)
82 blocks += loi->loi_blocks;
85 EXPORT_SYMBOL(lov_merge_blocks);
87 __u64 lov_merge_mtime(struct lov_stripe_md *lsm, __u64 current_time)
89 struct lov_oinfo *loi;
92 for (i = 0, loi = lsm->lsm_oinfo; i < lsm->lsm_stripe_count; i++, loi++)
93 if (loi->loi_mtime > current_time)
94 current_time = loi->loi_mtime;
97 EXPORT_SYMBOL(lov_merge_mtime);
99 /* Must be called under the lov_stripe_lock() */
100 int lov_adjust_kms(struct obd_export *exp, struct lov_stripe_md *lsm,
101 obd_off size, int shrink)
103 struct lov_oinfo *loi;
108 LASSERT_SPIN_LOCKED(&lsm->lsm_lock);
110 LASSERT(lsm->lsm_lock_owner == current);
114 struct lov_oinfo *loi;
115 for (loi = lsm->lsm_oinfo; stripe < lsm->lsm_stripe_count;
117 kms = lov_size_to_stripe(lsm, size, stripe);
118 loi->loi_kms = loi->loi_rss = kms;
120 "stripe %d KMS %sing "LPU64"->"LPU64"\n",
121 stripe, kms > loi->loi_kms ? "increas":"shrink",
128 stripe = lov_stripe_number(lsm, size - 1);
129 kms = lov_size_to_stripe(lsm, size, stripe);
130 loi = &(lsm->lsm_oinfo[stripe]);
132 CDEBUG(D_INODE, "stripe %d KMS %sincreasing "LPU64"->"LPU64"\n",
133 stripe, kms > loi->loi_kms ? "" : "not ", loi->loi_kms, kms);
134 if (kms > loi->loi_kms)
140 void lov_merge_attrs(struct obdo *tgt, struct obdo *src, obd_flag valid,
141 struct lov_stripe_md *lsm, int stripeno, int *set)
143 valid &= src->o_valid;
146 if (valid & OBD_MD_FLSIZE) {
147 /* this handles sparse files properly */
150 lov_size = lov_stripe_size(lsm, src->o_size, stripeno);
151 if (lov_size > tgt->o_size)
152 tgt->o_size = lov_size;
154 if (valid & OBD_MD_FLBLOCKS)
155 tgt->o_blocks += src->o_blocks;
156 if (valid & OBD_MD_FLBLKSZ)
157 tgt->o_blksize += src->o_blksize;
158 if (valid & OBD_MD_FLCTIME && tgt->o_ctime < src->o_ctime)
159 tgt->o_ctime = src->o_ctime;
160 if (valid & OBD_MD_FLMTIME && tgt->o_mtime < src->o_mtime)
161 tgt->o_mtime = src->o_mtime;
163 memcpy(tgt, src, sizeof(*tgt));
164 tgt->o_id = lsm->lsm_object_id;
165 if (valid & OBD_MD_FLSIZE)
166 tgt->o_size = lov_stripe_size(lsm,src->o_size,stripeno);