X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Fosd-zfs%2Fosd_io.c;h=a6b6cea2f2c7696044f0706076a29b692d0fced8;hb=685b0943eb4fe55720458326a5d6c4949457bf7a;hp=c283cdc294e4989e80f6ca3d92603962ae6ab984;hpb=b59942cce0ed3b720ec38c3b5a25063d01b8d218;p=fs%2Flustre-release.git diff --git a/lustre/osd-zfs/osd_io.c b/lustre/osd-zfs/osd_io.c index c283cdc..a6b6cea 100644 --- a/lustre/osd-zfs/osd_io.c +++ b/lustre/osd-zfs/osd_io.c @@ -27,7 +27,7 @@ * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. * - * Copyright (c) 2012, 2014, Intel Corporation. + * Copyright (c) 2012, 2015, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -49,7 +49,7 @@ #include #include #include -#include /* LLOG_CHUNK_SIZE definition */ +#include /* LLOG_MIN_CHUNK_SIZE definition */ #include "osd_internal.h" @@ -112,8 +112,7 @@ static void record_end_io(struct osd_device *osd, int rw, } static ssize_t osd_read(const struct lu_env *env, struct dt_object *dt, - struct lu_buf *buf, loff_t *pos, - struct lustre_capa *capa) + struct lu_buf *buf, loff_t *pos) { struct osd_object *obj = osd_dt_obj(dt); struct osd_device *osd = osd_obj2dev(obj); @@ -184,9 +183,9 @@ static ssize_t osd_declare_write(const struct lu_env *env, struct dt_object *dt, /* XXX: we still miss for append declaration support in ZFS * -1 means append which is used by llog mostly, llog - * can grow upto LLOG_CHUNK_SIZE*8 records */ + * can grow upto LLOG_MIN_CHUNK_SIZE*8 records */ if (pos == -1) - pos = max_t(loff_t, 256 * 8 * LLOG_CHUNK_SIZE, + pos = max_t(loff_t, 256 * 8 * LLOG_MIN_CHUNK_SIZE, obj->oo_attr.la_size + (2 << 20)); dmu_tx_hold_write(oh->ot_tx, oid, pos, buf->lb_len); @@ -200,8 +199,7 @@ static ssize_t osd_declare_write(const struct lu_env *env, struct dt_object *dt, static ssize_t osd_write(const struct lu_env *env, struct dt_object *dt, const struct lu_buf *buf, loff_t *pos, - struct thandle *th, struct lustre_capa *capa, - int ignore_quota) + struct thandle *th, int ignore_quota) { struct osd_object *obj = osd_dt_obj(dt); struct osd_device *osd = osd_obj2dev(obj); @@ -369,12 +367,12 @@ static int osd_bufs_get_read(const struct lu_env *env, struct osd_object *obj, lnb->lnb_rc = 0; lnb->lnb_file_offset = off; - lnb->lnb_page_offset = bufoff & ~CFS_PAGE_MASK; + lnb->lnb_page_offset = bufoff & ~PAGE_MASK; lnb->lnb_len = thispage; lnb->lnb_page = kmem_to_page(dbp[i]->db_data + bufoff); /* mark just a single slot: we need this - * reference to dbuf to be release once */ + * reference to dbuf to be released once */ lnb->lnb_data = dbf; dbf = NULL; @@ -387,7 +385,8 @@ static int osd_bufs_get_read(const struct lu_env *env, struct osd_object *obj, lnb++; } - /* steal dbuf so dmu_buf_rele_array() cant release it */ + /* steal dbuf so dmu_buf_rele_array() can't release + * it */ dbp[i] = NULL; } @@ -511,7 +510,7 @@ out_err: static int osd_bufs_get(const struct lu_env *env, struct dt_object *dt, loff_t offset, ssize_t len, struct niobuf_local *lnb, - int rw, struct lustre_capa *capa) + int rw) { struct osd_object *obj = osd_dt_obj(dt); int rc; @@ -538,83 +537,44 @@ static int osd_write_prep(const struct lu_env *env, struct dt_object *dt, return 0; } -/* Return number of blocks that aren't mapped in the [start, start + size] - * region */ -static int osd_count_not_mapped(struct osd_object *obj, uint64_t start, - uint32_t size) +static inline uint32_t osd_get_blocksz(struct osd_object *obj) { - dmu_buf_impl_t *dbi = (dmu_buf_impl_t *)obj->oo_db; - dmu_buf_impl_t *db; - dnode_t *dn; - uint32_t blkshift; - uint64_t end, blkid; - int rc; - ENTRY; - - DB_DNODE_ENTER(dbi); - dn = DB_DNODE(dbi); - - if (dn->dn_maxblkid == 0) { - if (start + size <= dn->dn_datablksz) - GOTO(out, size = 0); - if (start < dn->dn_datablksz) - start = dn->dn_datablksz; - /* assume largest block size */ - blkshift = SPA_MAXBLOCKSHIFT; - } else { - /* blocksize can't change */ - blkshift = dn->dn_datablkshift; - } + uint32_t blksz; + u_longlong_t unused; - /* compute address of last block */ - end = (start + size - 1) >> blkshift; - /* align start on block boundaries */ - start >>= blkshift; + LASSERT(obj->oo_db); - /* size is null, can't be mapped */ - if (obj->oo_attr.la_size == 0 || dn->dn_maxblkid == 0) - GOTO(out, size = (end - start + 1) << blkshift); + dmu_object_size_from_db(obj->oo_db, &blksz, &unused); + return blksz; +} - /* beyond EOF, can't be mapped */ - if (start > dn->dn_maxblkid) - GOTO(out, size = (end - start + 1) << blkshift); +static inline uint64_t osd_roundup2blocksz(uint64_t size, + uint64_t offset, + uint32_t blksz) +{ + LASSERT(blksz > 0); - size = 0; - for (blkid = start; blkid <= end; blkid++) { - if (blkid == dn->dn_maxblkid) - /* this one is mapped for sure */ - continue; - if (blkid > dn->dn_maxblkid) { - size += (end - blkid + 1) << blkshift; - GOTO(out, size); - } + size += offset % blksz; - rc = dbuf_hold_impl(dn, 0, blkid, TRUE, FTAG, &db); - if (rc) { - /* for ENOENT (block not mapped) and any other errors, - * assume the block isn't mapped */ - size += 1 << blkshift; - continue; - } - dbuf_rele(db, FTAG); - } + if (likely(IS_PO2(blksz))) + return PO2_ROUNDUP_TYPED(size, blksz, uint64_t); - GOTO(out, size); -out: - DB_DNODE_EXIT(dbi); - return size; + size += blksz - 1; + do_div(size, blksz); + return size * blksz; } static int osd_declare_write_commit(const struct lu_env *env, - struct dt_object *dt, - struct niobuf_local *lnb, int npages, - struct thandle *th) + struct dt_object *dt, + struct niobuf_local *lnb, int npages, + struct thandle *th) { struct osd_object *obj = osd_dt_obj(dt); struct osd_device *osd = osd_obj2dev(obj); struct osd_thandle *oh; uint64_t offset = 0; uint32_t size = 0; + uint32_t blksz = osd_get_blocksz(obj); int i, rc, flags = 0; bool ignore_quota = false, synced = false; long long space = 0; @@ -667,11 +627,13 @@ static int osd_declare_write_commit(const struct lu_env *env, dmu_tx_hold_write(oh->ot_tx, obj->oo_db->db_object, offset, size); - /* estimating space that will be consumed by a write is rather + /* Estimating space to be consumed by a write is rather * complicated with ZFS. As a consequence, we don't account for - * indirect blocks and quota overrun will be adjusted once the - * operation is committed, if required. */ - space += osd_count_not_mapped(obj, offset, size); + * indirect blocks and just use as a rough estimate the worse + * case where the old space is being held by a snapshot. Quota + * overrun will be adjusted once the operation is committed, if + * required. */ + space += osd_roundup2blocksz(size, offset, blksz); offset = lnb[i].lnb_file_offset; size = lnb[i].lnb_len; @@ -680,7 +642,7 @@ static int osd_declare_write_commit(const struct lu_env *env, if (size) { dmu_tx_hold_write(oh->ot_tx, obj->oo_db->db_object, offset, size); - space += osd_count_not_mapped(obj, offset, size); + space += osd_roundup2blocksz(size, offset, blksz); } dmu_tx_hold_sa(oh->ot_tx, obj->oo_sa_hdl, 0); @@ -691,8 +653,8 @@ static int osd_declare_write_commit(const struct lu_env *env, * copies */ space *= osd->od_os->os_copies; space = toqb(space); - CDEBUG(D_QUOTA, "writting %d pages, reserving "LPD64"K of quota " - "space\n", npages, space); + CDEBUG(D_QUOTA, "writing %d pages, reserving "LPD64"K of quota space\n", + npages, space); record_start_io(osd, WRITE, discont_pages); retry: @@ -809,7 +771,6 @@ static int osd_read_prep(const struct lu_env *env, struct dt_object *dt, { struct osd_object *obj = osd_dt_obj(dt); int i; - unsigned long size = 0; loff_t eof; LASSERT(dt_object_exists(dt)); @@ -824,12 +785,12 @@ static int osd_read_prep(const struct lu_env *env, struct dt_object *dt, continue; lnb[i].lnb_rc = lnb[i].lnb_len; - size += lnb[i].lnb_rc; - if (lnb[i].lnb_file_offset + lnb[i].lnb_len > eof) { - lnb[i].lnb_rc = eof - lnb[i].lnb_file_offset; - if (lnb[i].lnb_rc < 0) + if (lnb[i].lnb_file_offset + lnb[i].lnb_len >= eof) { + if (eof <= lnb[i].lnb_file_offset) lnb[i].lnb_rc = 0; + else + lnb[i].lnb_rc = eof - lnb[i].lnb_file_offset; /* all subsequent rc should be 0 */ while (++i < npages) @@ -876,8 +837,7 @@ static int __osd_object_punch(objset_t *os, dmu_buf_t *db, dmu_tx_t *tx, } static int osd_punch(const struct lu_env *env, struct dt_object *dt, - __u64 start, __u64 end, struct thandle *th, - struct lustre_capa *capa) + __u64 start, __u64 end, struct thandle *th) { struct osd_object *obj = osd_dt_obj(dt); struct osd_device *osd = osd_obj2dev(obj); @@ -946,6 +906,20 @@ static int osd_declare_punch(const struct lu_env *env, struct dt_object *dt, false)); } +static int osd_ladvise(const struct lu_env *env, struct dt_object *dt, + __u64 start, __u64 end, enum lu_ladvise_type advice) +{ + int rc; + ENTRY; + + switch (advice) { + default: + rc = -ENOTSUPP; + break; + } + + RETURN(rc); +} struct dt_body_operations osd_body_ops = { .dbo_read = osd_read, @@ -959,4 +933,5 @@ struct dt_body_operations osd_body_ops = { .dbo_read_prep = osd_read_prep, .dbo_declare_punch = osd_declare_punch, .dbo_punch = osd_punch, + .dbo_ladvise = osd_ladvise, };