1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
38 # define EXPORT_SYMTAB
40 #define DEBUG_SUBSYSTEM S_LOV
43 #include <libcfs/libcfs.h>
45 #include <liblustre.h>
48 #include <obd_class.h>
51 #include "lov_internal.h"
53 /* Merge the lock value block(&lvb) attributes from each of the stripes in a
54 * file into a single lvb. It is expected that the caller initializes the
55 * current atime, mtime, ctime to avoid regressing a more uptodate time on
58 * If @kms_only is set then we do not consider the recently seen size (rss)
59 * when updating the known minimum size (kms). Even when merging RSS, we will
60 * take the KMS value if it's larger. This prevents getattr from stomping on
61 * dirty cached pages which extend the file size. */
62 int lov_merge_lvb(struct obd_export *exp, struct lov_stripe_md *lsm,
63 struct ost_lvb *lvb, int kms_only)
65 struct lov_oinfo *loi;
68 __u64 current_mtime = lvb->lvb_mtime;
69 __u64 current_atime = lvb->lvb_atime;
70 __u64 current_ctime = lvb->lvb_ctime;
74 LASSERT_SPIN_LOCKED(&lsm->lsm_lock);
76 LASSERT(lsm->lsm_lock_owner == cfs_current());
79 for (i = 0; i < lsm->lsm_stripe_count; i++) {
80 obd_size lov_size, tmpsize;
82 loi = lsm->lsm_oinfo[i];
83 if (OST_LVB_IS_ERR(loi->loi_lvb.lvb_blocks)) {
84 rc = OST_LVB_GET_ERR(loi->loi_lvb.lvb_blocks);
88 tmpsize = loi->loi_kms;
89 if (kms_only == 0 && loi->loi_lvb.lvb_size > tmpsize)
90 tmpsize = loi->loi_lvb.lvb_size;
92 lov_size = lov_stripe_size(lsm, tmpsize, i);
95 /* merge blocks, mtime, atime, ctime */
96 blocks += loi->loi_lvb.lvb_blocks;
97 if (loi->loi_lvb.lvb_mtime > current_mtime)
98 current_mtime = loi->loi_lvb.lvb_mtime;
99 if (loi->loi_lvb.lvb_atime > current_atime)
100 current_atime = loi->loi_lvb.lvb_atime;
101 if (loi->loi_lvb.lvb_ctime > current_ctime)
102 current_ctime = loi->loi_lvb.lvb_ctime;
105 lvb->lvb_size = size;
106 lvb->lvb_blocks = blocks;
107 lvb->lvb_mtime = current_mtime;
108 lvb->lvb_atime = current_atime;
109 lvb->lvb_ctime = current_ctime;
113 /* Must be called under the lov_stripe_lock() */
114 int lov_adjust_kms(struct obd_export *exp, struct lov_stripe_md *lsm,
115 obd_off size, int shrink)
117 struct lov_oinfo *loi;
122 LASSERT_SPIN_LOCKED(&lsm->lsm_lock);
124 LASSERT(lsm->lsm_lock_owner == cfs_current());
128 struct lov_oinfo *loi;
129 for (; stripe < lsm->lsm_stripe_count; stripe++) {
130 loi = lsm->lsm_oinfo[stripe];
131 kms = lov_size_to_stripe(lsm, size, stripe);
133 "stripe %d KMS %sing "LPU64"->"LPU64"\n",
134 stripe, kms > loi->loi_kms ? "increas" :
135 kms < loi->loi_kms ? "shrink" : "leav",
137 loi->loi_kms = loi->loi_lvb.lvb_size = kms;
143 stripe = lov_stripe_number(lsm, size - 1);
144 kms = lov_size_to_stripe(lsm, size, stripe);
145 loi = lsm->lsm_oinfo[stripe];
147 CDEBUG(D_INODE, "stripe %d KMS %sincreasing "LPU64"->"LPU64"\n",
148 stripe, kms > loi->loi_kms ? "" : "not ", loi->loi_kms, kms);
149 if (kms > loi->loi_kms)
155 void lov_merge_attrs(struct obdo *tgt, struct obdo *src, obd_flag valid,
156 struct lov_stripe_md *lsm, int stripeno, int *set)
158 valid &= src->o_valid;
161 if (valid & OBD_MD_FLSIZE) {
162 /* this handles sparse files properly */
165 lov_size = lov_stripe_size(lsm, src->o_size, stripeno);
166 if (lov_size > tgt->o_size)
167 tgt->o_size = lov_size;
169 if (valid & OBD_MD_FLBLOCKS)
170 tgt->o_blocks += src->o_blocks;
171 if (valid & OBD_MD_FLBLKSZ)
172 tgt->o_blksize += src->o_blksize;
173 if (valid & OBD_MD_FLCTIME && tgt->o_ctime < src->o_ctime)
174 tgt->o_ctime = src->o_ctime;
175 if (valid & OBD_MD_FLMTIME && tgt->o_mtime < src->o_mtime)
176 tgt->o_mtime = src->o_mtime;
178 memcpy(tgt, src, sizeof(*tgt));
179 tgt->o_id = lsm->lsm_object_id;
180 tgt->o_gr = lsm->lsm_object_gr;
181 if (valid & OBD_MD_FLSIZE)
182 tgt->o_size = lov_stripe_size(lsm,src->o_size,stripeno);
187 int lov_update_lvb(struct obd_export *exp, struct lov_stripe_md *lsm,
188 struct ost_lvb *lvb, obd_flag valid)
191 struct lov_oinfo *loi;
193 LASSERT_SPIN_LOCKED(&lsm->lsm_lock);
194 LASSERT(lsm->lsm_lock_owner == cfs_current());
196 for (i = 0; i < lsm->lsm_stripe_count; i++) {
197 loi = lsm->lsm_oinfo[i];
198 if (valid & OBD_MD_FLATIME)
199 loi->loi_lvb.lvb_atime = lvb->lvb_atime;
200 if (valid & OBD_MD_FLMTIME)
201 loi->loi_lvb.lvb_mtime = lvb->lvb_mtime;
202 if (valid & OBD_MD_FLCTIME)
203 loi->loi_lvb.lvb_ctime = lvb->lvb_ctime;