Whamcloud - gitweb
LU-2675 mdt: add mbo_ prefix to members of struct mdt_body
[fs/lustre-release.git] / lustre / llite / llite_close.c
index 3fdf87a..ec01572 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.
  * GPL HEADER END
  */
 /*
- * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
+ *
+ * Copyright (c) 2011, 2012, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 
 #define DEBUG_SUBSYSTEM S_LLITE
 
-//#include <lustre_mdc.h>
 #include <lustre_lite.h>
 #include "llite_internal.h"
 
 /** records that a write is in flight */
 void vvp_write_pending(struct ccc_object *club, struct ccc_page *page)
 {
-        struct ll_inode_info *lli = ll_i2info(club->cob_inode);
-
-        ENTRY;
-        spin_lock(&lli->lli_lock);
-        lli->lli_flags |= LLIF_SOM_DIRTY;
-        if (page != NULL && list_empty(&page->cpg_pending_linkage))
-                list_add(&page->cpg_pending_linkage, &club->cob_pending_list);
-        spin_unlock(&lli->lli_lock);
-        EXIT;
+       struct ll_inode_info *lli = ll_i2info(club->cob_inode);
+
+       ENTRY;
+       spin_lock(&lli->lli_lock);
+       lli->lli_flags |= LLIF_SOM_DIRTY;
+       if (page != NULL && list_empty(&page->cpg_pending_linkage))
+               list_add(&page->cpg_pending_linkage,
+                            &club->cob_pending_list);
+       spin_unlock(&lli->lli_lock);
+       EXIT;
 }
 
 /** records that a write has completed */
 void vvp_write_complete(struct ccc_object *club, struct ccc_page *page)
 {
-        struct ll_inode_info *lli = ll_i2info(club->cob_inode);
-        int rc = 0;
-
-        ENTRY;
-        spin_lock(&lli->lli_lock);
-        if (page != NULL && !list_empty(&page->cpg_pending_linkage)) {
-                list_del_init(&page->cpg_pending_linkage);
-                rc = 1;
-        }
-        spin_unlock(&lli->lli_lock);
-        if (rc)
-                ll_queue_done_writing(club->cob_inode, 0);
-        EXIT;
+       struct ll_inode_info *lli = ll_i2info(club->cob_inode);
+       int rc = 0;
+
+       ENTRY;
+       spin_lock(&lli->lli_lock);
+       if (page != NULL && !list_empty(&page->cpg_pending_linkage)) {
+               list_del_init(&page->cpg_pending_linkage);
+               rc = 1;
+       }
+       spin_unlock(&lli->lli_lock);
+       if (rc)
+               ll_queue_done_writing(club->cob_inode, 0);
+       EXIT;
 }
 
 /** Queues DONE_WRITING if
@@ -83,43 +83,43 @@ void vvp_write_complete(struct ccc_object *club, struct ccc_page *page)
  * - inode has no no dirty pages; */
 void ll_queue_done_writing(struct inode *inode, unsigned long flags)
 {
-        struct ll_inode_info *lli = ll_i2info(inode);
-        struct ccc_object *club = cl2ccc(ll_i2info(inode)->lli_clob);
-        ENTRY;
+       struct ll_inode_info *lli = ll_i2info(inode);
+       struct ccc_object *club = cl2ccc(ll_i2info(inode)->lli_clob);
+       ENTRY;
 
-        spin_lock(&lli->lli_lock);
+       spin_lock(&lli->lli_lock);
         lli->lli_flags |= flags;
 
         if ((lli->lli_flags & LLIF_DONE_WRITING) &&
-            list_empty(&club->cob_pending_list)) {
+           list_empty(&club->cob_pending_list)) {
                 struct ll_close_queue *lcq = ll_i2sbi(inode)->ll_lcq;
 
                 if (lli->lli_flags & LLIF_MDS_SIZE_LOCK)
-                         CWARN("ino %lu/%u(flags %lu) som valid it just after "
-                               "recovery\n",
-                               inode->i_ino, inode->i_generation,
-                               lli->lli_flags);
-                /* DONE_WRITING is allowed and inode has no dirty page. */
-                spin_lock(&lcq->lcq_lock);
-
-                LASSERT(list_empty(&lli->lli_close_list));
-                CDEBUG(D_INODE, "adding inode %lu/%u to close list\n",
-                       inode->i_ino, inode->i_generation);
-                list_add_tail(&lli->lli_close_list, &lcq->lcq_head);
-
-                /* Avoid a concurrent insertion into the close thread queue:
-                 * an inode is already in the close thread, open(), write(),
-                 * close() happen, epoch is closed as the inode is marked as
-                 * LLIF_EPOCH_PENDING. When pages are written inode should not
-                 * be inserted into the queue again, clear this flag to avoid
-                 * it. */
-                lli->lli_flags &= ~LLIF_DONE_WRITING;
-
-                wake_up(&lcq->lcq_waitq);
-                spin_unlock(&lcq->lcq_lock);
-        }
-        spin_unlock(&lli->lli_lock);
-        EXIT;
+                       CWARN("%s: file "DFID"(flags %u) Size-on-MDS valid, "
+                             "done writing allowed and no diry pages\n",
+                             ll_get_fsname(inode->i_sb, NULL, 0),
+                             PFID(ll_inode2fid(inode)), lli->lli_flags);
+               /* DONE_WRITING is allowed and inode has no dirty page. */
+               spin_lock(&lcq->lcq_lock);
+
+               LASSERT(list_empty(&lli->lli_close_list));
+               CDEBUG(D_INODE, "adding inode "DFID" to close list\n",
+                      PFID(ll_inode2fid(inode)));
+               list_add_tail(&lli->lli_close_list, &lcq->lcq_head);
+
+               /* Avoid a concurrent insertion into the close thread queue:
+                * an inode is already in the close thread, open(), write(),
+                * close() happen, epoch is closed as the inode is marked as
+                * LLIF_EPOCH_PENDING. When pages are written inode should not
+                * be inserted into the queue again, clear this flag to avoid
+                * it. */
+               lli->lli_flags &= ~LLIF_DONE_WRITING;
+
+               wake_up(&lcq->lcq_waitq);
+               spin_unlock(&lcq->lcq_lock);
+       }
+       spin_unlock(&lli->lli_lock);
+       EXIT;
 }
 
 /** Pack SOM attributes info @opdata for CLOSE, DONE_WRITING rpc. */
@@ -131,9 +131,10 @@ void ll_done_writing_attr(struct inode *inode, struct md_op_data *op_data)
         op_data->op_flags |= MF_SOM_CHANGE;
         /* Check if Size-on-MDS attributes are valid. */
         if (lli->lli_flags & LLIF_MDS_SIZE_LOCK)
-                CERROR("ino %lu/%u(flags %lu) som valid it just after "
-                       "recovery\n", inode->i_ino, inode->i_generation,
-                       lli->lli_flags);
+               CERROR("%s: inode "DFID"(flags %u) MDS holds lock on "
+                      "Size-on-MDS attributes\n",
+                      ll_get_fsname(inode->i_sb, NULL, 0),
+                      PFID(ll_inode2fid(inode)), lli->lli_flags);
 
         if (!cl_local_size(inode)) {
                 /* Send Size-on-MDS Attributes if valid. */
@@ -145,22 +146,22 @@ void ll_done_writing_attr(struct inode *inode, struct md_op_data *op_data)
 
 /** Closes ioepoch and packs Size-on-MDS attribute if needed into @op_data. */
 void ll_ioepoch_close(struct inode *inode, struct md_op_data *op_data,
-                      struct obd_client_handle **och, unsigned long flags)
+                     struct obd_client_handle **och, unsigned long flags)
 {
-        struct ll_inode_info *lli = ll_i2info(inode);
-        struct ccc_object *club = cl2ccc(ll_i2info(inode)->lli_clob);
-        ENTRY;
-
-        spin_lock(&lli->lli_lock);
-        if (!(list_empty(&club->cob_pending_list))) {
-                if (!(lli->lli_flags & LLIF_EPOCH_PENDING)) {
-                        LASSERT(*och != NULL);
-                        LASSERT(lli->lli_pending_och == NULL);
-                        /* Inode is dirty and there is no pending write done
-                         * request yet, DONE_WRITE is to be sent later. */
-                        lli->lli_flags |= LLIF_EPOCH_PENDING;
-                        lli->lli_pending_och = *och;
-                        spin_unlock(&lli->lli_lock);
+       struct ll_inode_info *lli = ll_i2info(inode);
+       struct ccc_object *club = cl2ccc(ll_i2info(inode)->lli_clob);
+       ENTRY;
+
+       spin_lock(&lli->lli_lock);
+       if (!(list_empty(&club->cob_pending_list))) {
+               if (!(lli->lli_flags & LLIF_EPOCH_PENDING)) {
+                       LASSERT(*och != NULL);
+                       LASSERT(lli->lli_pending_och == NULL);
+                       /* Inode is dirty and there is no pending write done
+                        * request yet, DONE_WRITE is to be sent later. */
+                       lli->lli_flags |= LLIF_EPOCH_PENDING;
+                       lli->lli_pending_och = *och;
+                       spin_unlock(&lli->lli_lock);
 
                         inode = igrab(inode);
                         LASSERT(inode);
@@ -172,7 +173,7 @@ void ll_ioepoch_close(struct inode *inode, struct md_op_data *op_data,
                          * and try DONE_WRITE again later. */
                         LASSERT(!(lli->lli_flags & LLIF_DONE_WRITING));
                         lli->lli_flags |= LLIF_DONE_WRITING;
-                        spin_unlock(&lli->lli_lock);
+                       spin_unlock(&lli->lli_lock);
 
                         inode = igrab(inode);
                         LASSERT(inode);
@@ -192,26 +193,26 @@ void ll_ioepoch_close(struct inode *inode, struct md_op_data *op_data,
         } else {
                 /* Pack Size-on-MDS inode attributes only if they has changed */
                 if (!(lli->lli_flags & LLIF_SOM_DIRTY)) {
-                        spin_unlock(&lli->lli_lock);
-                        GOTO(out, 0);
-                }
-
-                /* There is a pending DONE_WRITE -- close epoch with no
-                 * attribute change. */
-                if (lli->lli_flags & LLIF_EPOCH_PENDING) {
-                        spin_unlock(&lli->lli_lock);
-                        GOTO(out, 0);
-                }
-        }
-
-        LASSERT(list_empty(&club->cob_pending_list));
-        lli->lli_flags &= ~LLIF_SOM_DIRTY;
-        spin_unlock(&lli->lli_lock);
-        ll_done_writing_attr(inode, op_data);
-
-        EXIT;
+                       spin_unlock(&lli->lli_lock);
+                       GOTO(out, 0);
+               }
+
+               /* There is a pending DONE_WRITE -- close epoch with no
+                * attribute change. */
+               if (lli->lli_flags & LLIF_EPOCH_PENDING) {
+                       spin_unlock(&lli->lli_lock);
+                       GOTO(out, 0);
+               }
+       }
+
+       LASSERT(list_empty(&club->cob_pending_list));
+       lli->lli_flags &= ~LLIF_SOM_DIRTY;
+       spin_unlock(&lli->lli_lock);
+       ll_done_writing_attr(inode, op_data);
+
+       EXIT;
 out:
-        return;
+       return;
 }
 
 /**
@@ -222,15 +223,17 @@ int ll_som_update(struct inode *inode, struct md_op_data *op_data)
 {
         struct ll_inode_info *lli = ll_i2info(inode);
         struct ptlrpc_request *request = NULL;
+        __u32 old_flags;
         struct obdo *oa;
         int rc;
         ENTRY;
 
         LASSERT(op_data != NULL);
         if (lli->lli_flags & LLIF_MDS_SIZE_LOCK)
-                CERROR("ino %lu/%u(flags %lu) som valid it just after "
-                       "recovery\n", inode->i_ino, inode->i_generation,
-                       lli->lli_flags);
+               CERROR("%s: inode "DFID"(flags %u) MDS holds lock on "
+                      "Size-on-MDS attributes\n",
+                      ll_get_fsname(inode->i_sb, NULL, 0),
+                      PFID(ll_inode2fid(inode)), lli->lli_flags);
 
         OBDO_ALLOC(oa);
         if (!oa) {
@@ -238,21 +241,21 @@ int ll_som_update(struct inode *inode, struct md_op_data *op_data)
                 RETURN(-ENOMEM);
         }
 
+        old_flags = op_data->op_flags;
         op_data->op_flags = MF_SOM_CHANGE;
 
         /* If inode is already in another epoch, skip getattr from OSTs. */
         if (lli->lli_ioepoch == op_data->op_ioepoch) {
-                rc = ll_inode_getattr(inode, oa, op_data->op_ioepoch);
+                rc = ll_inode_getattr(inode, oa, op_data->op_ioepoch,
+                                      old_flags & MF_GETATTR_LOCK);
                 if (rc) {
                         oa->o_valid = 0;
-                        if (rc == -ENOENT)
-                                CDEBUG(D_INODE, "objid "LPX64" is destroyed\n",
-                                       lli->lli_smd->lsm_object_id);
-                        else
-                                CERROR("inode_getattr failed (%d): unable to "
-                                       "send a Size-on-MDS attribute update "
-                                       "for inode %lu/%u\n", rc, inode->i_ino,
-                                       inode->i_generation);
+                       if (rc != -ENOENT)
+                               CERROR("%s: inode_getattr failed - unable to "
+                                      "send a Size-on-MDS attribute update "
+                                      "for inode "DFID": rc = %d\n",
+                                      ll_get_fsname(inode->i_sb, NULL, 0),
+                                      PFID(ll_inode2fid(inode)), rc);
                 } else {
                         CDEBUG(D_INODE, "Size-on-MDS update on "DFID"\n",
                                PFID(&lli->lli_fid));
@@ -315,8 +318,9 @@ static void ll_done_writing(struct inode *inode)
                  * OSTs and send setattr to back to MDS. */
                 rc = ll_som_update(inode, op_data);
         } else if (rc) {
-                CERROR("inode %lu mdc done_writing failed: rc = %d\n",
-                       inode->i_ino, rc);
+               CERROR("%s: inode "DFID" mdc done_writing failed: rc = %d\n",
+                      ll_get_fsname(inode->i_sb, NULL, 0),
+                      PFID(ll_inode2fid(inode)), rc);
         }
 out:
         ll_finish_md_op_data(op_data);
@@ -329,19 +333,19 @@ out:
 
 static struct ll_inode_info *ll_close_next_lli(struct ll_close_queue *lcq)
 {
-        struct ll_inode_info *lli = NULL;
+       struct ll_inode_info *lli = NULL;
 
-        spin_lock(&lcq->lcq_lock);
+       spin_lock(&lcq->lcq_lock);
 
-        if (!list_empty(&lcq->lcq_head)) {
-                lli = list_entry(lcq->lcq_head.next, struct ll_inode_info,
-                                 lli_close_list);
-                list_del_init(&lli->lli_close_list);
-        } else if (atomic_read(&lcq->lcq_stop))
-                lli = ERR_PTR(-EALREADY);
+       if (!list_empty(&lcq->lcq_head)) {
+               lli = list_entry(lcq->lcq_head.next, struct ll_inode_info,
+                                lli_close_list);
+               list_del_init(&lli->lli_close_list);
+       } else if (atomic_read(&lcq->lcq_stop))
+               lli = ERR_PTR(-EALREADY);
 
-        spin_unlock(&lcq->lcq_lock);
-        return lli;
+       spin_unlock(&lcq->lcq_lock);
+       return lli;
 }
 
 static int ll_close_thread(void *arg)
@@ -349,13 +353,7 @@ static int ll_close_thread(void *arg)
         struct ll_close_queue *lcq = arg;
         ENTRY;
 
-        {
-                char name[CFS_CURPROC_COMM_MAX];
-                snprintf(name, sizeof(name) - 1, "ll_close");
-                cfs_daemonize(name);
-        }
-
-        complete(&lcq->lcq_comp);
+       complete(&lcq->lcq_comp);
 
         while (1) {
                 struct l_wait_info lwi = { 0 };
@@ -369,50 +367,50 @@ static int ll_close_thread(void *arg)
                         break;
 
                 inode = ll_info2i(lli);
-                CDEBUG(D_INFO, "done_writting for inode %lu/%u\n",
-                       inode->i_ino, inode->i_generation);
+               CDEBUG(D_INFO, "done_writting for inode "DFID"\n",
+                      PFID(ll_inode2fid(inode)));
                 ll_done_writing(inode);
                 iput(inode);
         }
 
         CDEBUG(D_INFO, "ll_close exiting\n");
-        complete(&lcq->lcq_comp);
-        RETURN(0);
+       complete(&lcq->lcq_comp);
+       RETURN(0);
 }
 
 int ll_close_thread_start(struct ll_close_queue **lcq_ret)
 {
-        struct ll_close_queue *lcq;
-        pid_t pid;
-
-        if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CLOSE_THREAD))
-                return -EINTR;
-
-        OBD_ALLOC(lcq, sizeof(*lcq));
-        if (lcq == NULL)
-                return -ENOMEM;
-
-        spin_lock_init(&lcq->lcq_lock);
-        INIT_LIST_HEAD(&lcq->lcq_head);
-        init_waitqueue_head(&lcq->lcq_waitq);
-        init_completion(&lcq->lcq_comp);
-
-        pid = kernel_thread(ll_close_thread, lcq, 0);
-        if (pid < 0) {
-                OBD_FREE(lcq, sizeof(*lcq));
-                return pid;
-        }
-
-        wait_for_completion(&lcq->lcq_comp);
-        *lcq_ret = lcq;
-        return 0;
+       struct ll_close_queue *lcq;
+       struct task_struct *task;
+
+       if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CLOSE_THREAD))
+               return -EINTR;
+
+       OBD_ALLOC(lcq, sizeof(*lcq));
+       if (lcq == NULL)
+               return -ENOMEM;
+
+       spin_lock_init(&lcq->lcq_lock);
+       INIT_LIST_HEAD(&lcq->lcq_head);
+       init_waitqueue_head(&lcq->lcq_waitq);
+       init_completion(&lcq->lcq_comp);
+
+       task = kthread_run(ll_close_thread, lcq, "ll_close");
+       if (IS_ERR(task)) {
+               OBD_FREE(lcq, sizeof(*lcq));
+               return PTR_ERR(task);
+       }
+
+       wait_for_completion(&lcq->lcq_comp);
+       *lcq_ret = lcq;
+       return 0;
 }
 
 void ll_close_thread_shutdown(struct ll_close_queue *lcq)
 {
-        init_completion(&lcq->lcq_comp);
-        atomic_inc(&lcq->lcq_stop);
-        wake_up(&lcq->lcq_waitq);
-        wait_for_completion(&lcq->lcq_comp);
-        OBD_FREE(lcq, sizeof(*lcq));
+       init_completion(&lcq->lcq_comp);
+       atomic_inc(&lcq->lcq_stop);
+       wake_up(&lcq->lcq_waitq);
+       wait_for_completion(&lcq->lcq_comp);
+       OBD_FREE(lcq, sizeof(*lcq));
 }