Whamcloud - gitweb
LU-1816 scrub: OI scrub skips new created objects for once
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_io.c
index 08f26ab..35e08f8 100644 (file)
@@ -1,6 +1,4 @@
-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
- *
+/*
  * GPL HEADER START
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
@@ -353,6 +351,7 @@ static int osd_do_bio(struct osd_device *osd, struct inode *inode,
 
                         bio->bi_bdev = inode->i_sb->s_bdev;
                         bio->bi_sector = sector;
+                       bio->bi_rw = (iobuf->dr_rw == 0) ? READ : WRITE;
                         bio->bi_end_io = dio_complete_routine;
                         bio->bi_private = iobuf;
 
@@ -693,6 +692,7 @@ static int osd_write_commit(const struct lu_env *env, struct dt_object *dt,
 
         osd_init_iobuf(osd, iobuf, 1);
         isize = i_size_read(inode);
+       ll_vfs_dq_init(inode);
 
         for (i = 0; i < npages; i++) {
                 if (lnb[i].rc == -ENOSPC &&
@@ -851,12 +851,11 @@ static int osd_ldiskfs_readlink(struct inode *inode, char *buffer, int buflen)
         return  buflen;
 }
 
-static int osd_ldiskfs_read(struct inode *inode, void *buf, int size,
-                            loff_t *offs)
+int osd_ldiskfs_read(struct inode *inode, void *buf, int size, loff_t *offs)
 {
         struct buffer_head *bh;
         unsigned long block;
-        int osize = size;
+        int osize;
         int blocksize;
         int csize;
         int boffs;
@@ -879,15 +878,16 @@ static int osd_ldiskfs_read(struct inode *inode, void *buf, int size,
         }
 
         blocksize = 1 << inode->i_blkbits;
+        osize = size;
         while (size > 0) {
                 block = *offs >> inode->i_blkbits;
                 boffs = *offs & (blocksize - 1);
                 csize = min(blocksize - boffs, size);
                 bh = ldiskfs_bread(NULL, inode, block, 0, &err);
                 if (!bh) {
-                        CERROR("%s: error reading offset %llu (block %lu): "
-                               "rc = %d\n",
-                               inode->i_sb->s_id, *offs, block, err);
+                        CERROR("%s: can't read %u@%llu on ino %lu: rc = %d\n",
+                               LDISKFS_SB(inode->i_sb)->s_es->s_volume_name,
+                               csize, *offs, inode->i_ino, err);
                         return err;
                 }
 
@@ -971,8 +971,8 @@ static int osd_ldiskfs_writelink(struct inode *inode, char *buffer, int buflen)
         return 0;
 }
 
-static int osd_ldiskfs_write_record(struct inode *inode, void *buf, int bufsize,
-                                    loff_t *offs, handle_t *handle)
+int osd_ldiskfs_write_record(struct inode *inode, void *buf, int bufsize,
+                            int write_NUL, loff_t *offs, handle_t *handle)
 {
         struct buffer_head *bh        = NULL;
         loff_t              offset    = *offs;
@@ -984,6 +984,15 @@ static int osd_ldiskfs_write_record(struct inode *inode, void *buf, int bufsize,
         int                 boffs;
         int                 dirty_inode = 0;
 
+       if (write_NUL) {
+               /*
+                * long symlink write does not count the NUL terminator in
+                * bufsize, we write it, and the inode's file size does not
+                * count the NUL terminator as well.
+                */
+               ((char *)buf)[bufsize] = '\0';
+               ++bufsize;
+       }
         while (bufsize > 0) {
                 if (bh != NULL)
                         brelse(bh);
@@ -1022,6 +1031,8 @@ static int osd_ldiskfs_write_record(struct inode *inode, void *buf, int bufsize,
         if (bh)
                 brelse(bh);
 
+       if (write_NUL)
+               --new_size;
         /* correct in-core and on-disk sizes */
         if (new_size > i_size_read(inode)) {
                 cfs_spin_lock(&inode->i_lock);
@@ -1046,12 +1057,13 @@ static ssize_t osd_write(const struct lu_env *env, struct dt_object *dt,
                          struct thandle *handle, struct lustre_capa *capa,
                          int ignore_quota)
 {
-        struct inode       *inode = osd_dt_obj(dt)->oo_inode;
-        struct osd_thandle *oh;
-        ssize_t             result;
+       struct inode            *inode = osd_dt_obj(dt)->oo_inode;
+       struct osd_thandle      *oh;
+       ssize_t                 result;
 #ifdef HAVE_QUOTA_SUPPORT
-        cfs_cap_t           save = cfs_curproc_cap_pack();
+       cfs_cap_t               save = cfs_curproc_cap_pack();
 #endif
+       int                     is_link;
 
         LASSERT(dt_object_exists(dt));
 
@@ -1071,16 +1083,18 @@ static ssize_t osd_write(const struct lu_env *env, struct dt_object *dt,
         else
                 cfs_cap_lower(CFS_CAP_SYS_RESOURCE);
 #endif
-        /* Write small symlink to inode body as we need to maintain correct
-         * on-disk symlinks for ldiskfs.
-         */
-        if (S_ISLNK(dt->do_lu.lo_header->loh_attr) &&
-            (buf->lb_len < sizeof(LDISKFS_I(inode)->i_data)))
-                result = osd_ldiskfs_writelink(inode, buf->lb_buf, buf->lb_len);
-        else
-                result = osd_ldiskfs_write_record(inode, buf->lb_buf,
-                                                  buf->lb_len, pos,
-                                                  oh->ot_handle);
+       /* Write small symlink to inode body as we need to maintain correct
+        * on-disk symlinks for ldiskfs.
+        * Note: the buf->lb_buf contains a NUL terminator while buf->lb_len
+        * does not count it in.
+        */
+       is_link = S_ISLNK(dt->do_lu.lo_header->loh_attr);
+       if (is_link && (buf->lb_len < sizeof(LDISKFS_I(inode)->i_data)))
+               result = osd_ldiskfs_writelink(inode, buf->lb_buf, buf->lb_len);
+       else
+               result = osd_ldiskfs_write_record(inode, buf->lb_buf,
+                                                 buf->lb_len, is_link, pos,
+                                                 oh->ot_handle);
 #ifdef HAVE_QUOTA_SUPPORT
         cfs_curproc_cap_unpack(save);
 #endif