Whamcloud - gitweb
LU-4482 grant: don't use cache data in osd_statfs()
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_handler.c
index 375d057..3fd2e4c 100644 (file)
@@ -353,7 +353,7 @@ check_oi:
                LASSERTF(rc == -ESTALE || rc == -ENOENT, "rc = %d\n", rc);
 
                rc = osd_oi_lookup(info, dev, fid, id, OI_CHECK_FLD);
-               /* XXX: There are three possible cases:
+               /* XXX: There are some possible cases:
                 *      1. rc = 0.
                 *         Backup/restore caused the OI invalid.
                 *      2. rc = 0.
@@ -931,7 +931,7 @@ static void osd_trans_commit_cb(struct super_block *sb,
 
         lu_context_exit(&th->th_ctx);
         lu_context_fini(&th->th_ctx);
-        OBD_FREE_PTR(oh);
+       thandle_put(th);
 }
 
 static struct thandle *osd_trans_create(const struct lu_env *env,
@@ -956,7 +956,9 @@ static struct thandle *osd_trans_create(const struct lu_env *env,
                 th->th_result = 0;
                 th->th_tags = LCT_TX_HANDLE;
                 oh->ot_credits = 0;
-                oti->oti_dev = osd_dt_dev(d);
+               atomic_set(&th->th_refc, 1);
+               th->th_alloc_size = sizeof(*oh);
+               oti->oti_dev = osd_dt_dev(d);
                 CFS_INIT_LIST_HEAD(&oh->ot_dcb_list);
                 osd_th_alloced(oh);
 
@@ -1097,7 +1099,8 @@ static int osd_seq_exists(const struct lu_env *env,
 /*
  * Concurrency: shouldn't matter.
  */
-static int osd_trans_stop(const struct lu_env *env, struct thandle *th)
+static int osd_trans_stop(const struct lu_env *env, struct dt_device *dt,
+                         struct thandle *th)
 {
         int                     rc = 0;
         struct osd_thandle     *oh;
@@ -1140,7 +1143,7 @@ static int osd_trans_stop(const struct lu_env *env, struct thandle *th)
                 if (rc != 0)
                         CERROR("Failure to stop transaction: %d\n", rc);
         } else {
-                OBD_FREE_PTR(oh);
+               thandle_put(&oh->ot_super);
         }
 
        /* as we want IO to journal and data IO be concurrent, we don't block
@@ -1242,6 +1245,8 @@ static int osd_object_print(const struct lu_env *env, void *cookie,
                     d ? d->id_ops->id_name : "plain");
 }
 
+#define GRANT_FOR_LOCAL_OIDS 32 /* 128kB for last_rcvd, quota files, ... */
+
 /*
  * Concurrency: shouldn't matter.
  */
@@ -1266,24 +1271,28 @@ int osd_statfs(const struct lu_env *env, struct dt_device *d,
         }
 
        spin_lock(&osd->od_osfs_lock);
-       /* cache 1 second */
-       if (cfs_time_before_64(osd->od_osfs_age, cfs_time_shift_64(-1))) {
-               result = sb->s_op->statfs(sb->s_root, ksfs);
-               if (likely(result == 0)) { /* N.B. statfs can't really fail */
-                       osd->od_osfs_age = cfs_time_current_64();
-                       statfs_pack(&osd->od_statfs, ksfs);
-                       if (sb->s_flags & MS_RDONLY)
-                               sfs->os_state = OS_STATE_READONLY;
-               }
+       result = sb->s_op->statfs(sb->s_root, ksfs);
+       if (likely(result == 0)) { /* N.B. statfs can't really fail */
+               statfs_pack(sfs, ksfs);
+               if (sb->s_flags & MS_RDONLY)
+                       sfs->os_state = OS_STATE_READONLY;
        }
 
-       if (likely(result == 0))
-               *sfs = osd->od_statfs;
        spin_unlock(&osd->od_osfs_lock);
 
-        if (unlikely(env == NULL))
+       if (unlikely(env == NULL))
                 OBD_FREE_PTR(ksfs);
 
+       /* Reserve a small amount of space for local objects like last_rcvd,
+        * llog, quota files, ... */
+       if (sfs->os_bavail <= GRANT_FOR_LOCAL_OIDS) {
+               sfs->os_bavail = 0;
+       } else {
+               sfs->os_bavail -= GRANT_FOR_LOCAL_OIDS;
+               /** Take out metadata overhead for indirect blocks */
+               sfs->os_bavail -= sfs->os_bavail >> (sb->s_blocksize_bits - 3);
+       }
+
         return result;
 }
 
@@ -2031,7 +2040,6 @@ static int osd_mkfile(struct osd_thread_info *info, struct osd_object *obj,
                /* For new created object, it must be consistent,
                 * and it is unnecessary to scrub against it. */
                ldiskfs_set_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB);
-               ldiskfs_clear_inode_state(inode, LDISKFS_STATE_LUSTRE_NO_OI);
                 obj->oo_inode = inode;
                 result = 0;
         } else {
@@ -2196,7 +2204,6 @@ static void osd_ah_init(const struct lu_env *env, struct dt_allocation_hint *ah,
 {
         LASSERT(ah);
 
-        memset(ah, 0, sizeof(*ah));
         ah->dah_parent = parent;
         ah->dah_mode = child_mode;
 }
@@ -2639,7 +2646,6 @@ static struct inode *osd_create_local_agent_inode(const struct lu_env *env,
                RETURN(local);
        }
 
-       ldiskfs_set_inode_state(local, LDISKFS_STATE_LUSTRE_NO_OI);
        /* Set special LMA flag for local agent inode */
        rc = osd_ea_fid_set(info, local, fid, 0, LMAI_AGENT);
        if (rc != 0) {
@@ -2972,6 +2978,9 @@ static int osd_xattr_set(const struct lu_env *env, struct dt_object *dt,
         if (osd_object_auth(env, dt, capa, CAPA_OPC_META_WRITE))
                 return -EACCES;
 
+       CDEBUG(D_INODE, DFID" set xattr '%s' with size %zd\n",
+              PFID(lu_object_fid(&dt->do_lu)), name, buf->lb_len);
+
        osd_trans_exec_op(env, handle, OSD_OT_XATTR_SET);
        if (fl & LU_XATTR_REPLACE)
                fs_flags |= XATTR_REPLACE;
@@ -4833,14 +4842,16 @@ static int osd_ldiskfs_it_fill(const struct lu_env *env,
         else
                up_read(&obj->oo_ext_idx_sem);
 
-        if (it->oie_rd_dirent == 0) {
-                result = -EIO;
-        } else {
-                it->oie_dirent = it->oie_buf;
-                it->oie_it_dirent = 1;
-        }
+       if (it->oie_rd_dirent == 0) {
+               /*If it does not get any dirent, it means it has been reached
+                *to the end of the dir */
+               it->oie_file.f_pos = ldiskfs_get_htree_eof(&it->oie_file);
+       } else {
+               it->oie_dirent = it->oie_buf;
+               it->oie_it_dirent = 1;
+       }
 
-        RETURN(result);
+       RETURN(result);
 }
 
 /**
@@ -5611,13 +5622,17 @@ static int osd_mount(const struct lu_env *env,
 #endif
 
        if (!LDISKFS_HAS_COMPAT_FEATURE(o->od_mnt->mnt_sb,
-           LDISKFS_FEATURE_COMPAT_HAS_JOURNAL)) {
+                                       LDISKFS_FEATURE_COMPAT_HAS_JOURNAL)) {
                CERROR("%s: device %s is mounted w/o journal\n", name, dev);
                GOTO(out_mnt, rc = -EINVAL);
        }
 
+#ifdef LDISKFS_MOUNT_DIRDATA
+       if (LDISKFS_HAS_INCOMPAT_FEATURE(o->od_mnt->mnt_sb,
+                                        LDISKFS_FEATURE_INCOMPAT_DIRDATA))
+               LDISKFS_SB(osd_sb(o))->s_mount_opt |= LDISKFS_MOUNT_DIRDATA;
+#endif
        inode = osd_sb(o)->s_root->d_inode;
-       ldiskfs_set_inode_state(inode, LDISKFS_STATE_LUSTRE_NO_OI);
        lu_local_obj_fid(fid, OSD_FS_ROOT_OID);
        rc = osd_ea_fid_set(info, inode, fid, LMAC_NOT_IN_OI, 0);
        if (rc != 0) {
@@ -5677,7 +5692,6 @@ static int osd_device_init0(const struct lu_env *env,
 
        spin_lock_init(&o->od_osfs_lock);
        mutex_init(&o->od_otable_mutex);
-       o->od_osfs_age = cfs_time_shift_64(-1000);
 
        o->od_capa_hash = init_capa_hash();
        if (o->od_capa_hash == NULL)