* Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
*
- * Copyright (c) 2012, 2014, Intel Corporation.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
+ * Copyright (c) 2012, 2016, Intel Corporation.
*/
/*
* lustre/ofd/ofd_grant.c
* Each client node is granted an initial amount of reserved space at connect
* time and gets additional space back from OST in bulk write reply.
*
+ * We actually support three different cases:
+ * - The client supports the new grant parameters (i.e. OBD_CONNECT_GRANT_PARAM)
+ * which means that all grant overhead calculation happens on the client side.
+ * The server reports at connect time the backend filesystem block size, the
+ * maximum extent size as well as the extent insertion cost and it is then up
+ * to the osc layer to the track dirty extents and consume grant accordingly
+ * (see osc_cache.c). In each bulk write request, the client provides how much
+ * grant space was consumed for this RPC.
+ * - The client does not support OBD_CONNECT_GRANT_PARAM and always assumes a
+ * a backend file system block size of 4KB. We then have two cases:
+ * - If the block size is really 4KB, then the client can deal with grant
+ * allocation for partial block writes, but won't take extent insertion cost
+ * into account. For such clients, we inflate grant by 100% on the server
+ * side. It means that when 32MB of grant is hold by the client, 64MB of
+ * grant space is actually reserved on the server. All grant counters
+ * provided by such a client are inflated by 100%.
+ * - The backend filesystem block size is bigger than 4KB, which isn't
+ * supported by the client. In this case, we emulate a 4KB block size and
+ * consume one block size on the server for each 4KB of grant returned to
+ * client. With a 128KB blocksize, it means that 32MB dirty pages of 4KB
+ * on the client will actually consume 1GB of grant on the server.
+ * All grant counters provided by such a client are inflated by the block
+ * size ratio.
+ *
* This file handles the core logic for:
* - grant allocation strategy
* - maintaining per-client as well as global grant space accounting
#include "ofd_internal.h"
-/* At least enough to send a couple of 1MB RPCs, even if not max sized */
-#define OFD_GRANT_CHUNK (2ULL * DT_MAX_BRW_SIZE)
-
/* Clients typically hold 2x their max_rpcs_in_flight of grant space */
#define OFD_GRANT_SHRINK_LIMIT(exp) (2ULL * 8 * exp_max_brw_size(exp))
-static inline u64 ofd_grant_from_cli(struct obd_export *exp,
- struct ofd_device *ofd, u64 val)
+/* Helpers to inflate/deflate grants for clients that do not support the grant
+ * parameters */
+static inline u64 ofd_grant_inflate(struct ofd_device *ofd, u64 val)
{
- if (ofd_grant_compat(exp, ofd))
- /* clients not supporting OBD_CONNECT_GRANT_PARAM actually
- * consume 4KB of grant per block, we should thus inflate
- * the grant counters to reflect what was actually consumed */
+ if (ofd->ofd_blockbits > COMPAT_BSIZE_SHIFT)
+ /* Client does not support such large block size, grant
+ * is thus inflated. We already significantly overestimate
+ * overhead, no need to add the extent tax in this case */
return val << (ofd->ofd_blockbits - COMPAT_BSIZE_SHIFT);
- return val;
+ /* client can deal with the block size, but does not support per-extent
+ * grant accounting, inflate grant by 100% for such clients */
+ return val << 1;
}
-static inline u64 ofd_grant_to_cli(struct obd_export *exp,
- struct ofd_device *ofd, u64 val)
+/* Companion of ofd_grant_inflate() */
+static inline u64 ofd_grant_deflate(struct ofd_device *ofd, u64 val)
{
- if (ofd_grant_compat(exp, ofd))
+ if (ofd->ofd_blockbits > COMPAT_BSIZE_SHIFT)
return val >> (ofd->ofd_blockbits - COMPAT_BSIZE_SHIFT);
- return val;
+ return val >> 1;
}
+/* Grant chunk is used as a unit for grant allocation. It should be inflated
+ * if the client does not support the grant paramaters.
+ * Check connection flag against \a data if not NULL. This is used during
+ * connection creation where exp->exp_connect_data isn't populated yet */
static inline u64 ofd_grant_chunk(struct obd_export *exp,
- struct ofd_device *ofd)
+ struct ofd_device *ofd,
+ struct obd_connect_data *data)
{
+ u64 chunk = exp_max_brw_size(exp);
+ u64 tax;
+
if (ofd_obd(ofd)->obd_self_export == exp)
/* Grant enough space to handle a big precreate request */
return OST_MAX_PRECREATE * ofd->ofd_dt_conf.ddp_inodespace / 2;
- if (ofd_grant_compat(exp, ofd))
+ if ((data == NULL && !ofd_grant_param_supp(exp)) ||
+ (data != NULL && !OCD_HAS_FLAG(data, GRANT_PARAM)))
/* Try to grant enough space to send a full-size RPC */
- return exp_max_brw_size(exp) <<
- (ofd->ofd_blockbits - COMPAT_BSIZE_SHIFT);
-
- /* Try to return enough to send two full RPCs, if needed */
- return exp_max_brw_size(exp) * 2;
+ return ofd_grant_inflate(ofd, chunk);
+
+ /* Try to return enough to send two full-size RPCs
+ * = 2 * (BRW_size + #extents_in_BRW * grant_tax) */
+ tax = 1ULL << ofd->ofd_blockbits; /* block size */
+ tax *= ofd->ofd_dt_conf.ddp_max_extent_blks; /* max extent size */
+ tax = (chunk + tax - 1) / tax; /* #extents in a RPC */
+ tax *= ofd->ofd_dt_conf.ddp_extent_tax; /* extent tax for a RPC */
+ chunk = (chunk + tax) * 2; /* we said two full RPCs */
+ return chunk;
}
/**
error = 1;
if (fed->fed_grant + fed->fed_pending > maxsize) {
CERROR("%s: cli %s/%p fed_grant(%ld) + fed_pending(%ld)"
- " > maxsize("LPU64")\n", obd->obd_name,
+ " > maxsize(%llu)\n", obd->obd_name,
exp->exp_client_uuid.uuid, exp, fed->fed_grant,
fed->fed_pending, maxsize);
spin_unlock(&obd->obd_dev_lock);
LBUG();
}
if (fed->fed_dirty > maxsize) {
- CERROR("%s: cli %s/%p fed_dirty(%ld) > maxsize("LPU64
+ CERROR("%s: cli %s/%p fed_dirty(%ld) > maxsize(%llu"
")\n", obd->obd_name, exp->exp_client_uuid.uuid,
exp, fed->fed_dirty, maxsize);
spin_unlock(&obd->obd_dev_lock);
tot_pending += fed->fed_pending;
tot_dirty += fed->fed_dirty;
}
- spin_unlock(&obd->obd_dev_lock);
+
+ /* exports about to be unlinked should also be taken into account since
+ * they might still hold pending grant space to be released at
+ * commit time */
+ list_for_each_entry(exp, &obd->obd_unlinked_exports, exp_obd_chain) {
+ struct filter_export_data *fed;
+ int error = 0;
+
+ fed = &exp->exp_filter_data;
+
+ if (fed->fed_grant < 0 || fed->fed_pending < 0 ||
+ fed->fed_dirty < 0)
+ error = 1;
+ if (fed->fed_grant + fed->fed_pending > maxsize) {
+ CERROR("%s: cli %s/%p fed_grant(%ld) + fed_pending(%ld)"
+ " > maxsize(%llu)\n", obd->obd_name,
+ exp->exp_client_uuid.uuid, exp, fed->fed_grant,
+ fed->fed_pending, maxsize);
+ spin_unlock(&obd->obd_dev_lock);
+ spin_unlock(&ofd->ofd_grant_lock);
+ LBUG();
+ }
+ if (fed->fed_dirty > maxsize) {
+ CERROR("%s: cli %s/%p fed_dirty(%ld) > maxsize(%llu"
+ ")\n", obd->obd_name, exp->exp_client_uuid.uuid,
+ exp, fed->fed_dirty, maxsize);
+ spin_unlock(&obd->obd_dev_lock);
+ spin_unlock(&ofd->ofd_grant_lock);
+ LBUG();
+ }
+ CDEBUG_LIMIT(error ? D_ERROR : D_CACHE, "%s: cli %s/%p dirty "
+ "%ld pend %ld grant %ld\n", obd->obd_name,
+ exp->exp_client_uuid.uuid, exp, fed->fed_dirty,
+ fed->fed_pending, fed->fed_grant);
+ tot_granted += fed->fed_grant + fed->fed_pending;
+ tot_pending += fed->fed_pending;
+ tot_dirty += fed->fed_dirty;
+ }
+
fo_tot_granted = ofd->ofd_tot_granted;
fo_tot_pending = ofd->ofd_tot_pending;
fo_tot_dirty = ofd->ofd_tot_dirty;
+ spin_unlock(&obd->obd_dev_lock);
+ spin_unlock(&ofd->ofd_grant_lock);
if (tot_granted != fo_tot_granted)
- CERROR("%s: tot_granted "LPU64" != fo_tot_granted "LPU64"\n",
+ CERROR("%s: tot_granted %llu != fo_tot_granted %llu\n",
func, tot_granted, fo_tot_granted);
if (tot_pending != fo_tot_pending)
- CERROR("%s: tot_pending "LPU64" != fo_tot_pending "LPU64"\n",
+ CERROR("%s: tot_pending %llu != fo_tot_pending %llu\n",
func, tot_pending, fo_tot_pending);
if (tot_dirty != fo_tot_dirty)
- CERROR("%s: tot_dirty "LPU64" != fo_tot_dirty "LPU64"\n",
+ CERROR("%s: tot_dirty %llu != fo_tot_dirty %llu\n",
func, tot_dirty, fo_tot_dirty);
if (tot_pending > tot_granted)
- CERROR("%s: tot_pending "LPU64" > tot_granted "LPU64"\n",
+ CERROR("%s: tot_pending %llu > tot_granted %llu\n",
func, tot_pending, tot_granted);
if (tot_granted > maxsize)
- CERROR("%s: tot_granted "LPU64" > maxsize "LPU64"\n",
+ CERROR("%s: tot_granted %llu > maxsize %llu\n",
func, tot_granted, maxsize);
if (tot_dirty > maxsize)
- CERROR("%s: tot_dirty "LPU64" > maxsize "LPU64"\n",
+ CERROR("%s: tot_dirty %llu > maxsize %llu\n",
func, tot_dirty, maxsize);
- spin_unlock(&ofd->ofd_grant_lock);
}
/**
return;
}
- CDEBUG(D_CACHE, "%s: cli %s/%p free: "LPU64" avail: "LPU64"\n",
+ CDEBUG(D_CACHE, "%s: cli %s/%p free: %llu avail: %llu\n",
obd->obd_name, exp->exp_client_uuid.uuid, exp,
osfs->os_bfree << ofd->ofd_blockbits,
osfs->os_bavail << ofd->ofd_blockbits);
tot_granted - ofd->ofd_tot_pending) ?
D_ERROR : D_CACHE;
- CDEBUG_LIMIT(mask, "%s: cli %s/%p left "LPU64" < tot_grant "
- LPU64" unstable "LPU64" pending "LPU64" "
- "dirty "LPU64"\n",
+ CDEBUG_LIMIT(mask, "%s: cli %s/%p left %llu < tot_grant "
+ "%llu unstable %llu pending %llu "
+ "dirty %llu\n",
obd->obd_name, exp->exp_client_uuid.uuid, exp,
left, tot_granted, unstable,
ofd->ofd_tot_pending, ofd->ofd_tot_dirty);
/* Withdraw space already granted to clients */
left -= tot_granted;
- /* If the left space is below the grant threshold x available space,
- * stop granting space to clients.
- * The purpose of this threshold is to keep some error margin on the
- * overhead estimate made by the OSD layer. If we grant all the free
- * space, we have no way (grant space cannot be revoked yet) to
- * adjust if the write overhead has been underestimated. */
- left -= min_t(u64, left, ofd_grant_reserved(ofd, avail));
-
/* Align left on block size */
left &= ~((1ULL << ofd->ofd_blockbits) - 1);
- CDEBUG(D_CACHE, "%s: cli %s/%p avail "LPU64" left "LPU64" unstable "
- LPU64" tot_grant "LPU64" pending "LPU64"\n", obd->obd_name,
+ CDEBUG(D_CACHE, "%s: cli %s/%p avail %llu left %llu unstable "
+ "%llu tot_grant %llu pending %llu\n", obd->obd_name,
exp->exp_client_uuid.uuid, exp, avail, left, unstable,
tot_granted, ofd->ofd_tot_pending);
/**
* Process grant information from obdo structure packed in incoming BRW
+ * and inflate grant counters if required.
*
- * Grab the dirty and seen grant announcements from the incoming obdo.
+ * Grab the dirty and seen grant announcements from the incoming obdo and
+ * inflate all grant counters passed in the request if the client does not
+ * support the grant parameters.
* We will later calculate the client's new grant and return it.
* Caller must hold ofd_grant_lock spinlock.
*
* \param[in] env LU environment supplying osfs storage
* \param[in] exp export for which we received the request
* \param[in,out] oa incoming obdo sent by the client
- *
*/
static void ofd_grant_incoming(const struct lu_env *env, struct obd_export *exp,
- struct obdo *oa)
+ struct obdo *oa, long chunk)
{
struct filter_export_data *fed;
struct ofd_device *ofd = ofd_exp(exp);
struct obd_device *obd = exp->exp_obd;
long dirty;
long dropped;
- long grant_chunk;
ENTRY;
assert_spin_locked(&ofd->ofd_grant_lock);
* out-or-order and have already consumed some grant. We want to
* leave this here in case there is a large error in accounting. */
CDEBUG(D_CACHE,
- "%s: cli %s/%p reports grant "LPU64" dropped %u, local %lu\n",
+ "%s: cli %s/%p reports grant %llu dropped %u, local %lu\n",
obd->obd_name, exp->exp_client_uuid.uuid, exp, oa->o_grant,
oa->o_dropped, fed->fed_grant);
if ((long long)oa->o_dirty < 0)
oa->o_dirty = 0;
- dirty = ofd_grant_from_cli(exp, ofd, oa->o_dirty);
- dropped = ofd_grant_from_cli(exp, ofd, (u64)oa->o_dropped);
- grant_chunk = ofd_grant_chunk(exp, ofd);
+ /* inflate grant counters if required */
+ if (!ofd_grant_param_supp(exp)) {
+ oa->o_grant = ofd_grant_inflate(ofd, oa->o_grant);
+ oa->o_dirty = ofd_grant_inflate(ofd, oa->o_dirty);
+ oa->o_dropped = ofd_grant_inflate(ofd, (u64)oa->o_dropped);
+ oa->o_undirty = ofd_grant_inflate(ofd, oa->o_undirty);
+ }
+
+ dirty = oa->o_dirty;
+ dropped = oa->o_dropped;
/* Update our accounting now so that statfs takes it into account.
* Note that fed_dirty is only approximate and can become incorrect
* if RPCs arrive out-of-order. No important calculations depend
* on fed_dirty however, but we must check sanity to not assert. */
- if (dirty > fed->fed_grant + 4 * grant_chunk)
- dirty = fed->fed_grant + 4 * grant_chunk;
+ if (dirty > fed->fed_grant + 4 * chunk)
+ dirty = fed->fed_grant + 4 * chunk;
ofd->ofd_tot_dirty += dirty - fed->fed_dirty;
if (fed->fed_grant < dropped) {
CDEBUG(D_CACHE,
dropped = 0;
}
if (ofd->ofd_tot_granted < dropped) {
- CERROR("%s: cli %s/%p reports %lu dropped > tot_grant "LPU64
- "\n", obd->obd_name, exp->exp_client_uuid.uuid, exp,
+ CERROR("%s: cli %s/%p reports %lu dropped > tot_grant %llu\n",
+ obd->obd_name, exp->exp_client_uuid.uuid, exp,
dropped, ofd->ofd_tot_granted);
dropped = 0;
}
OFD_GRANT_SHRINK_LIMIT(exp))
return;
- grant_shrink = ofd_grant_from_cli(exp, ofd, oa->o_grant);
+ grant_shrink = oa->o_grant;
fed = &exp->exp_filter_data;
fed->fed_grant -= grant_shrink;
ofd->ofd_tot_granted -= grant_shrink;
- CDEBUG(D_CACHE, "%s: cli %s/%p shrink %ld fed_grant %ld total "
- LPU64"\n", obd->obd_name, exp->exp_client_uuid.uuid,
- exp, grant_shrink, fed->fed_grant, ofd->ofd_tot_granted);
+ CDEBUG(D_CACHE, "%s: cli %s/%p shrink %ld fed_grant %ld total %llu\n",
+ obd->obd_name, exp->exp_client_uuid.uuid, exp, grant_shrink,
+ fed->fed_grant, ofd->ofd_tot_granted);
/* client has just released some grant, don't grant any space back */
oa->o_grant = 0;
* larger than the minimal supported page size (i.e. 4KB).
*
* \param[in] exp export associated which the write request
+ * if NULL, then size estimate is done for server-side
+ * grant allocation.
* \param[in] ofd ofd device handling the request
* \param[in] rnb network buffer to estimate size of
*
struct ofd_device *ofd,
struct niobuf_remote *rnb)
{
- u64 blocksize;
+ u64 blksize;
u64 bytes;
u64 end;
- if (exp && ofd_grant_compat(exp, ofd))
- blocksize = 1ULL << COMPAT_BSIZE_SHIFT;
+ if (exp && !ofd_grant_param_supp(exp) &&
+ ofd->ofd_blockbits > COMPAT_BSIZE_SHIFT)
+ blksize = 1ULL << COMPAT_BSIZE_SHIFT;
else
- blocksize = 1ULL << ofd->ofd_blockbits;
+ blksize = 1ULL << ofd->ofd_blockbits;
/* The network buffer might span several blocks, align it on block
* boundaries */
- bytes = rnb->rnb_offset & (blocksize - 1);
+ bytes = rnb->rnb_offset & (blksize - 1);
bytes += rnb->rnb_len;
- end = bytes & (blocksize - 1);
+ end = bytes & (blksize - 1);
if (end)
- bytes += blocksize - end;
- if (exp)
- /* Apply per-export pecularities if one is given */
- bytes = ofd_grant_from_cli(exp, ofd, bytes);
+ bytes += blksize - end;
+
+ if (exp == NULL || ofd_grant_param_supp(exp)) {
+ /* add per-extent insertion cost */
+ u64 max_ext;
+ int nr_ext;
+
+ max_ext = blksize * ofd->ofd_dt_conf.ddp_max_extent_blks;
+ nr_ext = (bytes + max_ext - 1) / max_ext;
+ bytes += nr_ext * ofd->ofd_dt_conf.ddp_extent_tax;
+ } else {
+ /* Inflate grant space if client does not support extent-based
+ * grant allocation */
+ bytes = ofd_grant_inflate(ofd, (u64)bytes);
+ }
+
return bytes;
}
unsigned long ungranted = 0;
unsigned long granted = 0;
int i;
- int resend = 0;
+ bool skip = false;
struct ofd_thread_info *info = ofd_info(env);
ENTRY;
assert_spin_locked(&ofd->ofd_grant_lock);
- if ((oa->o_valid & OBD_MD_FLFLAGS) &&
- (oa->o_flags & OBD_FL_RECOV_RESEND)) {
- resend = 1;
+ if (obd->obd_recovering) {
+ /* Replaying write. Grant info have been processed already so no
+ * need to do any enforcement here. It is worth noting that only
+ * bulk writes with all rnbs having OBD_BRW_FROM_GRANT can be
+ * replayed. If one page hasn't OBD_BRW_FROM_GRANT set, then
+ * the whole bulk is written synchronously */
+ skip = true;
+ CDEBUG(D_CACHE, "Replaying write, skipping accounting\n");
+ } else if ((oa->o_valid & OBD_MD_FLFLAGS) &&
+ (oa->o_flags & OBD_FL_RECOV_RESEND)) {
+ /* Recoverable resend, grant info have already been processed as
+ * well */
+ skip = true;
CDEBUG(D_CACHE, "Recoverable resend arrived, skipping "
"accounting\n");
+ } else if (ofd_grant_param_supp(exp) && oa->o_grant_used > 0) {
+ /* Client supports the new grant parameters and is telling us
+ * how much grant space it consumed for this bulk write.
+ * Although all rnbs are supposed to have the OBD_BRW_FROM_GRANT
+ * flag set, we will scan the rnb list and looks for non-cache
+ * I/O in case it changes in the future */
+ if (fed->fed_grant >= oa->o_grant_used) {
+ /* skip grant accounting for rnbs with
+ * OBD_BRW_FROM_GRANT and just used grant consumption
+ * claimed in the request */
+ granted = oa->o_grant_used;
+ skip = true;
+ } else {
+ /* client has used more grants for this request that
+ * it owns ... */
+ CERROR("%s: cli %s claims %lu GRANT, real grant %lu\n",
+ exp->exp_obd->obd_name,
+ exp->exp_client_uuid.uuid,
+ (unsigned long)oa->o_grant_used, fed->fed_grant);
+
+ /* check whether we can fill the gap with unallocated
+ * grant */
+ if (*left > (oa->o_grant_used - fed->fed_grant)) {
+ /* ouf .. we are safe for now */
+ granted = fed->fed_grant;
+ ungranted = oa->o_grant_used - granted;
+ *left -= ungranted;
+ skip = true;
+ }
+ /* too bad, but we cannot afford to blow up our grant
+ * accounting. The loop below will handle each rnb in
+ * case by case. */
+ }
}
for (i = 0; i < niocount; i++) {
int bytes;
- if (obd->obd_recovering) {
- /* Replaying write. Grant info have been processed
- * already so no need to do any enforcement here.
- * It is worth noting that only bulk writes with all
- * rnbs having OBD_BRW_FROM_GRANT can be replayed.
- * If one page hasn't OBD_BRW_FROM_GRANT set, then
- * the whole bulk is written synchronously */
- if (rnb[i].rnb_flags & OBD_BRW_FROM_GRANT) {
- rnb[i].rnb_flags |= OBD_BRW_GRANTED;
- continue;
- } else {
- CERROR("%s: cli %s is replaying OST_WRITE "
- "while one rnb hasn't OBD_BRW_FROM_GRANT"
- " set (0x%x)\n", exp->exp_obd->obd_name,
- exp->exp_client_uuid.uuid,
- rnb[i].rnb_flags);
-
- }
- } else if ((oa->o_valid & OBD_MD_FLGRANT) &&
- (rnb[i].rnb_flags & OBD_BRW_FROM_GRANT)) {
- if (resend) {
- /* This is a recoverable resend so grant
- * information have already been processed */
+ if ((rnb[i].rnb_flags & OBD_BRW_FROM_GRANT)) {
+ if (skip) {
rnb[i].rnb_flags |= OBD_BRW_GRANTED;
continue;
}
- /* inflate consumed space if needed */
+ /* compute how much grant space is actually needed for
+ * this rnb, inflate grant if required */
bytes = ofd_grant_rnb_size(exp, ofd, &rnb[i]);
- if (fed->fed_grant < granted + bytes) {
- CDEBUG(D_CACHE, "%s: cli %s/%p claims %ld+%d "
- "GRANT, real grant %lu idx %d\n",
- exp->exp_obd->obd_name,
- exp->exp_client_uuid.uuid, exp,
- granted, bytes, fed->fed_grant, i);
- } else {
+ if (fed->fed_grant >= granted + bytes) {
granted += bytes;
rnb[i].rnb_flags |= OBD_BRW_GRANTED;
continue;
}
+
+ CDEBUG(D_CACHE, "%s: cli %s/%p claims %ld+%d GRANT, "
+ "real grant %lu idx %d\n", obd->obd_name,
+ exp->exp_client_uuid.uuid, exp, granted, bytes,
+ fed->fed_grant, i);
}
+ if (obd->obd_recovering)
+ CERROR("%s: cli %s is replaying OST_WRITE while one rnb"
+ " hasn't OBD_BRW_FROM_GRANT set (0x%x)\n",
+ obd->obd_name, exp->exp_client_uuid.uuid,
+ rnb[i].rnb_flags);
+
/* Consume grant space on the server.
* Unlike above, ofd_grant_rnb_size() is called with exp = NULL
* so that the required grant space isn't inflated. This is
* done on purpose since the server can deal with large block
* size, unlike some clients */
bytes = ofd_grant_rnb_size(NULL, ofd, &rnb[i]);
- if (*left > ungranted + bytes) {
+ if (*left > bytes) {
/* if enough space, pretend it was granted */
ungranted += bytes;
+ *left -= bytes;
rnb[i].rnb_flags |= OBD_BRW_GRANTED;
continue;
}
/* We can't check for already-mapped blocks here (make sense
* when backend filesystem does not use COW) as it requires
* dropping the grant lock.
- * Instead, we clear ~OBD_BRW_GRANTED and in that case we need
+ * Instead, we clear OBD_BRW_GRANTED and in that case we need
* to go through and verify if all of the blocks not marked
* BRW_GRANTED are already mapped and we can ignore this error.
*/
rnb[i].rnb_flags &= ~OBD_BRW_GRANTED;
CDEBUG(D_CACHE,"%s: cli %s/%p idx %d no space for %d\n",
- exp->exp_obd->obd_name,
- exp->exp_client_uuid.uuid, exp, i, bytes);
+ obd->obd_name, exp->exp_client_uuid.uuid, exp, i, bytes);
}
+ /* record in o_grant_used the actual space reserved for the I/O, will be
+ * used later in ofd_grant_commmit() */
+ oa->o_grant_used = granted + ungranted;
+ info->fti_used = granted + ungranted;
+
/* record space used for the I/O, will be used in ofd_grant_commmit() */
/* Now substract what the clients has used already. We don't subtract
* this from the tot_granted yet, so that other client's can't grab
* that space before we have actually allocated our blocks. That
* happens in ofd_grant_commit() after the writes are done. */
- info->fti_used = granted + ungranted;
- *left -= ungranted;
fed->fed_grant -= granted;
- fed->fed_pending += info->fti_used;
+ fed->fed_pending += oa->o_grant_used;
ofd->ofd_tot_granted += ungranted;
- ofd->ofd_tot_pending += info->fti_used;
+ ofd->ofd_tot_pending += oa->o_grant_used;
CDEBUG(D_CACHE,
"%s: cli %s/%p granted: %lu ungranted: %lu grant: %lu dirty: %lu"
"\n", obd->obd_name, exp->exp_client_uuid.uuid, exp,
granted, ungranted, fed->fed_grant, fed->fed_dirty);
- if (obd->obd_recovering)
- /* don't update dirty accounting during recovery */
+ if (obd->obd_recovering || (oa->o_valid & OBD_MD_FLGRANT) == 0)
+ /* don't update dirty accounting during recovery or
+ * if grant information got discarded (e.g. during resend) */
RETURN_EXIT;
if (fed->fed_dirty < granted) {
* \retval amount of grant space allocated
*/
static long ofd_grant_alloc(struct obd_export *exp, u64 curgrant,
- u64 want, u64 left, bool conservative)
+ u64 want, u64 left, long chunk,
+ bool conservative)
{
struct obd_device *obd = exp->exp_obd;
struct ofd_device *ofd = ofd_exp(exp);
struct filter_export_data *fed = &exp->exp_filter_data;
- long grant_chunk;
u64 grant;
ENTRY;
RETURN(0);
if (want > 0x7fffffff) {
- CERROR("%s: client %s/%p requesting > 2GB grant "LPU64"\n",
+ CERROR("%s: client %s/%p requesting > 2GB grant %llu\n",
obd->obd_name, exp->exp_client_uuid.uuid, exp, want);
RETURN(0);
}
- /* client not supporting OBD_CONNECT_GRANT_PARAM works with a 4KB block
- * size while the reality is different */
- curgrant = ofd_grant_from_cli(exp, ofd, curgrant);
- want = ofd_grant_from_cli(exp, ofd, want);
- grant_chunk = ofd_grant_chunk(exp, ofd);
-
/* Grant some fraction of the client's requested grant space so that
* they are not always waiting for write credits (not all of it to
* avoid overgranting in face of multiple RPCs in flight). This
* has and what we think it has, don't grant very much and let the
* client consume its grant first. Either it just has lots of RPCs
* in flight, or it was evicted and its grants will soon be used up. */
- if (curgrant >= want || curgrant >= fed->fed_grant + grant_chunk)
- RETURN(0);
+ if (curgrant >= want || curgrant >= fed->fed_grant + chunk)
+ RETURN(0);
if (obd->obd_recovering)
conservative = false;
* one chunk */
left >>= 3;
grant = min(want - curgrant, left);
- /* round grant upt to the next block size */
+ /* round grant up to the next block size */
grant = (grant + (1 << ofd->ofd_blockbits) - 1) &
~((1ULL << ofd->ofd_blockbits) - 1);
if (!grant)
RETURN(0);
- /* Limit to ofd_grant_chunk() if not reconnect/recovery */
- if ((grant > grant_chunk) && conservative)
- grant = grant_chunk;
+ /* Limit to grant_chunk if not reconnect/recovery */
+ if ((grant > chunk) && conservative)
+ grant = chunk;
ofd->ofd_tot_granted += grant;
fed->fed_grant += grant;
if (fed->fed_grant < 0) {
- CERROR("%s: cli %s/%p grant %ld want "LPU64" current "LPU64"\n",
+ CERROR("%s: cli %s/%p grant %ld want %llu current %llu\n",
obd->obd_name, exp->exp_client_uuid.uuid, exp,
fed->fed_grant, want, curgrant);
spin_unlock(&ofd->ofd_grant_lock);
}
CDEBUG(D_CACHE,
- "%s: cli %s/%p wants: "LPU64" current grant "LPU64
- " granting: "LPU64"\n", obd->obd_name, exp->exp_client_uuid.uuid,
+ "%s: cli %s/%p wants: %llu current grant %llu"
+ " granting: %llu\n", obd->obd_name, exp->exp_client_uuid.uuid,
exp, want, curgrant, grant);
CDEBUG(D_CACHE,
- "%s: cli %s/%p tot cached:"LPU64" granted:"LPU64
+ "%s: cli %s/%p tot cached:%llu granted:%llu"
" num_exports: %d\n", obd->obd_name, exp->exp_client_uuid.uuid,
exp, ofd->ofd_tot_dirty, ofd->ofd_tot_granted,
obd->obd_num_exports);
- RETURN(ofd_grant_to_cli(exp, ofd, grant));
+ RETURN(grant);
}
/**
*
* \param[in] env LU environment provided by the caller
* \param[in] exp client's export which is (re)connecting
- * \param[in] want how much grant space the client would like to get
+ * \param[in,out] data obd_connect_data structure sent by the client in the
+ * connect request
* \param[in] new_conn must set to true if this is a new connection and false
* for a reconnection
- *
- * \retval amount of grant space currently owned by the client
*/
-long ofd_grant_connect(const struct lu_env *env, struct obd_export *exp,
- u64 want, bool new_conn)
+void ofd_grant_connect(const struct lu_env *env, struct obd_export *exp,
+ struct obd_connect_data *data, bool new_conn)
{
struct ofd_device *ofd = ofd_exp(exp);
struct filter_export_data *fed = &exp->exp_filter_data;
u64 left = 0;
- long grant;
+ u64 want;
+ long chunk;
int from_cache;
int force = 0; /* can use cached data */
/* don't grant space to client with read-only access */
- if ((exp_connect_flags(exp) & OBD_CONNECT_RDONLY) ||
- ofd_grant_prohibit(exp, ofd))
- return 0;
+ if (OCD_HAS_FLAG(data, RDONLY) ||
+ (!OCD_HAS_FLAG(data, GRANT_PARAM) &&
+ ofd->ofd_grant_compat_disable)) {
+ data->ocd_grant = 0;
+ data->ocd_connect_flags &= ~(OBD_CONNECT_GRANT |
+ OBD_CONNECT_GRANT_PARAM);
+ RETURN_EXIT;
+ }
+ if (OCD_HAS_FLAG(data, GRANT_PARAM))
+ want = data->ocd_grant;
+ else
+ want = ofd_grant_inflate(ofd, data->ocd_grant);
+ chunk = ofd_grant_chunk(exp, ofd, data);
refresh:
ofd_grant_statfs(env, exp, force, &from_cache);
left = ofd_grant_space_left(exp);
/* get fresh statfs data if we are short in ungranted space */
- if (from_cache && left < 32 * ofd_grant_chunk(exp, ofd)) {
+ if (from_cache && left < 32 * chunk) {
spin_unlock(&ofd->ofd_grant_lock);
CDEBUG(D_CACHE, "fs has no space left and statfs too old\n");
force = 1;
goto refresh;
}
- ofd_grant_alloc(exp,
- ofd_grant_to_cli(exp, ofd, (u64)fed->fed_grant),
- want, left, new_conn);
+ ofd_grant_alloc(exp, (u64)fed->fed_grant, want, left, chunk, new_conn);
/* return to client its current grant */
- grant = ofd_grant_to_cli(exp, ofd, (u64)fed->fed_grant);
- ofd->ofd_tot_granted_clients++;
+ if (OCD_HAS_FLAG(data, GRANT_PARAM))
+ data->ocd_grant = fed->fed_grant;
+ else
+ /* deflate grant */
+ data->ocd_grant = ofd_grant_deflate(ofd,
+ (u64)fed->fed_grant);
+
+ /* reset dirty accounting */
+ ofd->ofd_tot_dirty -= fed->fed_dirty;
+ fed->fed_dirty = 0;
+
+ if (new_conn && OCD_HAS_FLAG(data, GRANT))
+ ofd->ofd_tot_granted_clients++;
spin_unlock(&ofd->ofd_grant_lock);
- CDEBUG(D_CACHE, "%s: cli %s/%p ocd_grant: %ld want: "LPU64" left: "
- LPU64"\n", exp->exp_obd->obd_name, exp->exp_client_uuid.uuid,
- exp, grant, want, left);
+ CDEBUG(D_CACHE, "%s: cli %s/%p ocd_grant: %d want: %llu left: %llu\n",
+ exp->exp_obd->obd_name, exp->exp_client_uuid.uuid,
+ exp, data->ocd_grant, want, left);
- return grant;
+ EXIT;
}
/**
spin_lock(&ofd->ofd_grant_lock);
LASSERTF(ofd->ofd_tot_granted >= fed->fed_grant,
- "%s: tot_granted "LPU64" cli %s/%p fed_grant %ld\n",
+ "%s: tot_granted %llu cli %s/%p fed_grant %ld\n",
obd->obd_name, ofd->ofd_tot_granted,
exp->exp_client_uuid.uuid, exp, fed->fed_grant);
ofd->ofd_tot_granted -= fed->fed_grant;
fed->fed_grant = 0;
LASSERTF(ofd->ofd_tot_pending >= fed->fed_pending,
- "%s: tot_pending "LPU64" cli %s/%p fed_pending %ld\n",
+ "%s: tot_pending %llu cli %s/%p fed_pending %ld\n",
obd->obd_name, ofd->ofd_tot_pending,
exp->exp_client_uuid.uuid, exp, fed->fed_pending);
/* ofd_tot_pending is handled in ofd_grant_commit as bulk
- * finishes */
+ * commmits */
LASSERTF(ofd->ofd_tot_dirty >= fed->fed_dirty,
- "%s: tot_dirty "LPU64" cli %s/%p fed_dirty %ld\n",
+ "%s: tot_dirty %llu cli %s/%p fed_dirty %ld\n",
obd->obd_name, ofd->ofd_tot_dirty,
exp->exp_client_uuid.uuid, exp, fed->fed_dirty);
ofd->ofd_tot_dirty -= fed->fed_dirty;
struct ofd_device *ofd = ofd_exp(exp);
int do_shrink;
u64 left = 0;
+ ENTRY;
if (!oa)
- return;
+ RETURN_EXIT;
if ((oa->o_valid & OBD_MD_FLGRANT) == 0)
/* The read request does not contain any grant
* information */
- return;
+ RETURN_EXIT;
if ((oa->o_valid & OBD_MD_FLFLAGS) &&
(oa->o_flags & OBD_FL_SHRINK_GRANT)) {
do_shrink = 0;
}
- /* extract incoming grant infomation provided by the client */
- ofd_grant_incoming(env, exp, oa);
+ /* extract incoming grant information provided by the client and
+ * inflate grant counters if required */
+ ofd_grant_incoming(env, exp, oa, ofd_grant_chunk(exp, ofd, NULL));
/* unlike writes, we don't return grants back on reads unless a grant
* shrink request was packed and we decided to turn it down. */
else
oa->o_grant = 0;
+ if (!ofd_grant_param_supp(exp))
+ oa->o_grant = ofd_grant_deflate(ofd, oa->o_grant);
spin_unlock(&ofd->ofd_grant_lock);
+ EXIT;
}
/**
u64 left;
int from_cache;
int force = 0; /* can use cached data intially */
- int rc;
+ long chunk = ofd_grant_chunk(exp, ofd, NULL);
ENTRY;
left = ofd_grant_space_left(exp);
/* Get fresh statfs data if we are short in ungranted space */
- if (from_cache && left < 32 * ofd_grant_chunk(exp, ofd)) {
+ if (from_cache && left < 32 * chunk) {
spin_unlock(&ofd->ofd_grant_lock);
CDEBUG(D_CACHE, "%s: fs has no space left and statfs too old\n",
obd->obd_name);
/* When close to free space exhaustion, trigger a sync to force
* writeback cache to consume required space immediately and release as
* much space as possible. */
- if (!obd->obd_recovering && force != 2 && left < OFD_GRANT_CHUNK) {
+ if (!obd->obd_recovering && force != 2 && left < chunk) {
bool from_grant = true;
int i;
* space on the server */
spin_unlock(&ofd->ofd_grant_lock);
/* discard errors, at least we tried ... */
- rc = dt_sync(env, ofd->ofd_osd);
+ dt_sync(env, ofd->ofd_osd);
force = 2;
goto refresh;
}
}
- /* extract incoming grant information provided by the client */
- ofd_grant_incoming(env, exp, oa);
+ /* extract incoming grant information provided by the client,
+ * and inflate grant counters if required */
+ ofd_grant_incoming(env, exp, oa, chunk);
/* check limit */
ofd_grant_check(env, exp, oa, rnb, niocount, &left);
else
/* grant more space back to the client if possible */
oa->o_grant = ofd_grant_alloc(exp, oa->o_grant, oa->o_undirty,
- left, true);
+ left, chunk, true);
+
+ if (!ofd_grant_param_supp(exp))
+ oa->o_grant = ofd_grant_deflate(ofd, oa->o_grant);
spin_unlock(&ofd->ofd_grant_lock);
+ EXIT;
}
/**
* export currently)
* \param[in] nr number of objects to be created
*
- * \retval 0 for success
+ * \retval >= 0 amount of grant space allocated to the precreate request
* \retval -ENOSPC on failure
*/
-int ofd_grant_create(const struct lu_env *env, struct obd_export *exp, int *nr)
+long ofd_grant_create(const struct lu_env *env, struct obd_export *exp, int *nr)
{
- struct ofd_thread_info *info = ofd_info(env);
struct ofd_device *ofd = ofd_exp(exp);
struct filter_export_data *fed = &exp->exp_filter_data;
u64 left = 0;
unsigned long wanted;
+ unsigned long granted;
ENTRY;
- info->fti_used = 0;
-
if (exp->exp_obd->obd_recovering ||
ofd->ofd_dt_conf.ddp_inodespace == 0)
/* don't enforce grant during recovery */
if (ofd->ofd_osfs.os_bavail - (fed->fed_grant >> ofd->ofd_blockbits) <
(ofd->ofd_osfs.os_blocks >> 10)) {
spin_unlock(&ofd->ofd_grant_lock);
- CDEBUG(D_RPCTRACE, "%s: not enough space for create "LPU64"\n",
+ CDEBUG(D_RPCTRACE, "%s: not enough space for create %llu\n",
ofd_name(ofd),
ofd->ofd_osfs.os_bavail * ofd->ofd_osfs.os_blocks);
RETURN(-ENOSPC);
left -= wanted - fed->fed_grant;
fed->fed_grant = 0;
}
- info->fti_used = wanted;
- fed->fed_pending += info->fti_used;
- ofd->ofd_tot_pending += info->fti_used;
+ granted = wanted;
+ fed->fed_pending += granted;
+ ofd->ofd_tot_pending += granted;
/* grant more space for precreate purpose if possible. */
wanted = OST_MAX_PRECREATE * ofd->ofd_dt_conf.ddp_inodespace / 2;
if (wanted > fed->fed_grant) {
+ long chunk;
+
/* always try to book enough space to handle a large precreate
* request */
+ chunk = ofd_grant_chunk(exp, ofd, NULL);
wanted -= fed->fed_grant;
- ofd_grant_alloc(exp, fed->fed_grant, wanted, left, false);
+ ofd_grant_alloc(exp, fed->fed_grant, wanted, left, chunk,
+ false);
}
spin_unlock(&ofd->ofd_grant_lock);
- RETURN(0);
+ RETURN(granted);
}
/**
*
* Update pending grant counter once buffers have been written to the disk.
*
- * \param[in] env LU environment provided by the caller
* \param[in] exp export of the client which sent the request
+ * \param[in] pending amount of reserved space to be released
* \param[in] rc return code of pre-commit operations
*/
-void ofd_grant_commit(const struct lu_env *env, struct obd_export *exp,
+void ofd_grant_commit(struct obd_export *exp, unsigned long pending,
int rc)
{
struct ofd_device *ofd = ofd_exp(exp);
- struct ofd_thread_info *info = ofd_info(env);
- unsigned long pending;
-
ENTRY;
/* get space accounted in tot_pending for the I/O, set in
* ofd_grant_check() */
- pending = info->fti_used;
if (pending == 0)
RETURN_EXIT;
exp->exp_filter_data.fed_pending -= pending;
if (ofd->ofd_tot_granted < pending) {
- CERROR("%s: cli %s/%p tot_granted("LPU64") < grant_used(%lu)"
- "\n", exp->exp_obd->obd_name,
- exp->exp_client_uuid.uuid, exp, ofd->ofd_tot_granted,
- pending);
+ CERROR("%s: cli %s/%p tot_granted(%llu) < grant_used(%lu)\n",
+ exp->exp_obd->obd_name, exp->exp_client_uuid.uuid, exp,
+ ofd->ofd_tot_granted, pending);
spin_unlock(&ofd->ofd_grant_lock);
LBUG();
}
ofd->ofd_tot_granted -= pending;
if (ofd->ofd_tot_pending < pending) {
- CERROR("%s: cli %s/%p tot_pending("LPU64") < grant_used(%lu)"
- "\n", exp->exp_obd->obd_name, exp->exp_client_uuid.uuid,
- exp, ofd->ofd_tot_pending, pending);
+ CERROR("%s: cli %s/%p tot_pending(%llu) < grant_used(%lu)\n",
+ exp->exp_obd->obd_name, exp->exp_client_uuid.uuid, exp,
+ ofd->ofd_tot_pending, pending);
spin_unlock(&ofd->ofd_grant_lock);
LBUG();
}
spin_unlock(&ofd->ofd_grant_lock);
EXIT;
}
+
+struct ofd_grant_cb {
+ /* commit callback structure */
+ struct dt_txn_commit_cb ogc_cb;
+ /* export associated with the bulk write */
+ struct obd_export *ogc_exp;
+ /* pending grant to be released */
+ unsigned long ogc_granted;
+};
+
+/**
+ * Callback function for grant releasing
+ *
+ * Release grant space reserved by the client node.
+ *
+ * \param[in] env execution environment
+ * \param[in] th transaction handle
+ * \param[in] cb callback data
+ * \param[in] err error code
+ */
+static void ofd_grant_commit_cb(struct lu_env *env, struct thandle *th,
+ struct dt_txn_commit_cb *cb, int err)
+{
+ struct ofd_grant_cb *ogc;
+
+ ogc = container_of(cb, struct ofd_grant_cb, ogc_cb);
+
+ ofd_grant_commit(ogc->ogc_exp, ogc->ogc_granted, err);
+ class_export_cb_put(ogc->ogc_exp);
+ OBD_FREE_PTR(ogc);
+}
+
+/**
+ * Add callback for grant releasing
+ *
+ * Register a commit callback to release grant space.
+ *
+ * \param[in] th transaction handle
+ * \param[in] exp OBD export of client
+ * \param[in] granted amount of grant space to be released upon commit
+ *
+ * \retval 0 on successful callback adding
+ * \retval negative value on error
+ */
+int ofd_grant_commit_cb_add(struct thandle *th, struct obd_export *exp,
+ unsigned long granted)
+{
+ struct ofd_grant_cb *ogc;
+ struct dt_txn_commit_cb *dcb;
+ int rc;
+ ENTRY;
+
+ OBD_ALLOC_PTR(ogc);
+ if (ogc == NULL)
+ RETURN(-ENOMEM);
+
+ ogc->ogc_exp = class_export_cb_get(exp);
+ ogc->ogc_granted = granted;
+
+ dcb = &ogc->ogc_cb;
+ dcb->dcb_func = ofd_grant_commit_cb;
+ INIT_LIST_HEAD(&dcb->dcb_linkage);
+ strlcpy(dcb->dcb_name, "ofd_grant_commit_cb", sizeof(dcb->dcb_name));
+
+ rc = dt_trans_cb_add(th, dcb);
+ if (rc) {
+ class_export_cb_put(ogc->ogc_exp);
+ OBD_FREE_PTR(ogc);
+ }
+
+ RETURN(rc);
+}