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 <libcfs/libcfs.h>
33 #include <liblustre.h>
36 #include <obd_class.h>
39 #include "lov_internal.h"
41 /* Merge the lock value block(&lvb) attributes from each of the stripes in a
42 * file into a single lvb. It is expected that the caller initializes the
43 * current atime, mtime, ctime to avoid regressing a more uptodate time on
46 * If @kms_only is set then we do not consider the recently seen size (rss)
47 * when updating the known minimum size (kms). Even when merging RSS, we will
48 * take the KMS value if it's larger. This prevents getattr from stomping on
49 * dirty cached pages which extend the file size. */
50 int lov_merge_lvb(struct obd_export *exp, struct lov_stripe_md *lsm,
51 struct ost_lvb *lvb, int kms_only)
53 struct lov_oinfo *loi;
56 __u64 current_mtime = lvb->lvb_mtime;
57 __u64 current_atime = lvb->lvb_atime;
58 __u64 current_ctime = lvb->lvb_ctime;
62 LASSERT_SPIN_LOCKED(&lsm->lsm_lock);
64 LASSERT(lsm->lsm_lock_owner == cfs_current());
67 for (i = 0; i < lsm->lsm_stripe_count; i++) {
68 obd_size lov_size, tmpsize;
70 loi = lsm->lsm_oinfo[i];
71 if (OST_LVB_IS_ERR(loi->loi_lvb.lvb_blocks)) {
72 rc = OST_LVB_GET_ERR(loi->loi_lvb.lvb_blocks);
76 tmpsize = loi->loi_kms;
77 if (kms_only == 0 && loi->loi_lvb.lvb_size > tmpsize)
78 tmpsize = loi->loi_lvb.lvb_size;
80 lov_size = lov_stripe_size(lsm, tmpsize, i);
83 /* merge blocks, mtime, atime */
84 blocks += loi->loi_lvb.lvb_blocks;
85 if (loi->loi_lvb.lvb_atime > current_atime)
86 current_atime = loi->loi_lvb.lvb_atime;
88 /* mtime is always updated with ctime, but can be set in past.
89 As write and utime(2) may happen within 1 second, and utime's
90 mtime has a priority over write's one, leave mtime from mds
91 for the same ctimes. */
92 if (loi->loi_lvb.lvb_ctime > current_ctime) {
93 current_ctime = loi->loi_lvb.lvb_ctime;
94 current_mtime = loi->loi_lvb.lvb_mtime;
99 lvb->lvb_blocks = blocks;
100 lvb->lvb_mtime = current_mtime;
101 lvb->lvb_atime = current_atime;
102 lvb->lvb_ctime = current_ctime;
106 /* Must be called under the lov_stripe_lock() */
107 int lov_adjust_kms(struct obd_export *exp, struct lov_stripe_md *lsm,
108 obd_off size, int shrink)
110 struct lov_oinfo *loi;
115 LASSERT_SPIN_LOCKED(&lsm->lsm_lock);
117 LASSERT(lsm->lsm_lock_owner == cfs_current());
121 struct lov_oinfo *loi;
122 for (; stripe < lsm->lsm_stripe_count; stripe++) {
123 loi = lsm->lsm_oinfo[stripe];
124 kms = lov_size_to_stripe(lsm, size, stripe);
126 "stripe %d KMS %sing "LPU64"->"LPU64"\n",
127 stripe, kms > loi->loi_kms ? "increas" :
128 kms < loi->loi_kms ? "shrink" : "leav",
130 loi->loi_kms = loi->loi_lvb.lvb_size = kms;
136 stripe = lov_stripe_number(lsm, size - 1);
137 kms = lov_size_to_stripe(lsm, size, stripe);
138 loi = lsm->lsm_oinfo[stripe];
140 CDEBUG(D_INODE, "stripe %d KMS %sincreasing "LPU64"->"LPU64"\n",
141 stripe, kms > loi->loi_kms ? "" : "not ", loi->loi_kms, kms);
142 if (kms > loi->loi_kms)
148 void lov_merge_attrs(struct obdo *tgt, struct obdo *src, obd_flag valid,
149 struct lov_stripe_md *lsm, int stripeno, int *set)
151 valid &= src->o_valid;
154 if (valid & OBD_MD_FLSIZE) {
155 /* this handles sparse files properly */
158 lov_size = lov_stripe_size(lsm, src->o_size, stripeno);
159 if (lov_size > tgt->o_size)
160 tgt->o_size = lov_size;
162 if (valid & OBD_MD_FLBLOCKS)
163 tgt->o_blocks += src->o_blocks;
164 if (valid & OBD_MD_FLBLKSZ)
165 tgt->o_blksize += src->o_blksize;
166 if (valid & OBD_MD_FLCTIME && tgt->o_ctime < src->o_ctime)
167 tgt->o_ctime = src->o_ctime;
168 /* Only mtime from OSTs are merged here, as they cannot be set
169 in past (only MDS's mtime can) do not look at ctime. */
170 if (valid & OBD_MD_FLMTIME && tgt->o_mtime < src->o_mtime)
171 tgt->o_mtime = src->o_mtime;
173 memcpy(tgt, src, sizeof(*tgt));
174 tgt->o_id = lsm->lsm_object_id;
175 if (valid & OBD_MD_FLSIZE)
176 tgt->o_size = lov_stripe_size(lsm,src->o_size,stripeno);