Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1 | /* |
| 2 | * GPL HEADER START |
| 3 | * |
| 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 only, |
| 8 | * as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License version 2 for more details (a copy is included |
| 14 | * in the LICENSE file that accompanied this code). |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * version 2 along with this program; If not, see |
Oleg Drokin | 6a5b99a | 2016-06-14 23:33:40 -0400 | [diff] [blame] | 18 | * http://www.gnu.org/licenses/gpl-2.0.html |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 19 | * |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 20 | * GPL HEADER END |
| 21 | */ |
| 22 | /* |
| 23 | * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. |
| 24 | * Use is subject to license terms. |
| 25 | * |
| 26 | * Copyright (c) 2011, 2012, Intel Corporation. |
| 27 | */ |
| 28 | /* |
| 29 | * This file is part of Lustre, http://www.lustre.org/ |
| 30 | * Lustre is a trademark of Sun Microsystems, Inc. |
| 31 | * |
| 32 | * lustre/llite/llite_close.c |
| 33 | * |
| 34 | * Lustre Lite routines to issue a secondary close after writeback |
| 35 | */ |
| 36 | |
| 37 | #include <linux/module.h> |
| 38 | |
| 39 | #define DEBUG_SUBSYSTEM S_LLITE |
| 40 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 41 | #include "llite_internal.h" |
| 42 | |
| 43 | /** records that a write is in flight */ |
John L. Hammond | 3a52f80 | 2016-03-30 19:48:48 -0400 | [diff] [blame] | 44 | void vvp_write_pending(struct vvp_object *club, struct vvp_page *page) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 45 | { |
John L. Hammond | 8c7b0e1 | 2016-03-30 19:48:47 -0400 | [diff] [blame] | 46 | struct ll_inode_info *lli = ll_i2info(club->vob_inode); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 47 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 48 | spin_lock(&lli->lli_lock); |
| 49 | lli->lli_flags |= LLIF_SOM_DIRTY; |
John L. Hammond | 3a52f80 | 2016-03-30 19:48:48 -0400 | [diff] [blame] | 50 | if (page && list_empty(&page->vpg_pending_linkage)) |
| 51 | list_add(&page->vpg_pending_linkage, &club->vob_pending_list); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 52 | spin_unlock(&lli->lli_lock); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | /** records that a write has completed */ |
John L. Hammond | 3a52f80 | 2016-03-30 19:48:48 -0400 | [diff] [blame] | 56 | void vvp_write_complete(struct vvp_object *club, struct vvp_page *page) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 57 | { |
John L. Hammond | 8c7b0e1 | 2016-03-30 19:48:47 -0400 | [diff] [blame] | 58 | struct ll_inode_info *lli = ll_i2info(club->vob_inode); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 59 | int rc = 0; |
| 60 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 61 | spin_lock(&lli->lli_lock); |
John L. Hammond | 3a52f80 | 2016-03-30 19:48:48 -0400 | [diff] [blame] | 62 | if (page && !list_empty(&page->vpg_pending_linkage)) { |
| 63 | list_del_init(&page->vpg_pending_linkage); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 64 | rc = 1; |
| 65 | } |
| 66 | spin_unlock(&lli->lli_lock); |
| 67 | if (rc) |
John L. Hammond | 8c7b0e1 | 2016-03-30 19:48:47 -0400 | [diff] [blame] | 68 | ll_queue_done_writing(club->vob_inode, 0); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | /** Queues DONE_WRITING if |
| 72 | * - done writing is allowed; |
Oleg Drokin | c0894c6 | 2016-02-24 22:00:30 -0500 | [diff] [blame] | 73 | * - inode has no no dirty pages; |
| 74 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 75 | void ll_queue_done_writing(struct inode *inode, unsigned long flags) |
| 76 | { |
| 77 | struct ll_inode_info *lli = ll_i2info(inode); |
John L. Hammond | 8c7b0e1 | 2016-03-30 19:48:47 -0400 | [diff] [blame] | 78 | struct vvp_object *club = cl2vvp(ll_i2info(inode)->lli_clob); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 79 | |
| 80 | spin_lock(&lli->lli_lock); |
| 81 | lli->lli_flags |= flags; |
| 82 | |
| 83 | if ((lli->lli_flags & LLIF_DONE_WRITING) && |
John L. Hammond | 8c7b0e1 | 2016-03-30 19:48:47 -0400 | [diff] [blame] | 84 | list_empty(&club->vob_pending_list)) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 85 | struct ll_close_queue *lcq = ll_i2sbi(inode)->ll_lcq; |
| 86 | |
| 87 | if (lli->lli_flags & LLIF_MDS_SIZE_LOCK) |
James Nunez | 97a075c | 2016-04-27 18:21:01 -0400 | [diff] [blame] | 88 | CWARN("%s: file "DFID"(flags %u) Size-on-MDS valid, done writing allowed and no diry pages\n", |
| 89 | ll_get_fsname(inode->i_sb, NULL, 0), |
| 90 | PFID(ll_inode2fid(inode)), lli->lli_flags); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 91 | /* DONE_WRITING is allowed and inode has no dirty page. */ |
| 92 | spin_lock(&lcq->lcq_lock); |
| 93 | |
| 94 | LASSERT(list_empty(&lli->lli_close_list)); |
James Nunez | 97a075c | 2016-04-27 18:21:01 -0400 | [diff] [blame] | 95 | CDEBUG(D_INODE, "adding inode "DFID" to close list\n", |
| 96 | PFID(ll_inode2fid(inode))); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 97 | list_add_tail(&lli->lli_close_list, &lcq->lcq_head); |
| 98 | |
| 99 | /* Avoid a concurrent insertion into the close thread queue: |
| 100 | * an inode is already in the close thread, open(), write(), |
| 101 | * close() happen, epoch is closed as the inode is marked as |
| 102 | * LLIF_EPOCH_PENDING. When pages are written inode should not |
| 103 | * be inserted into the queue again, clear this flag to avoid |
Oleg Drokin | c0894c6 | 2016-02-24 22:00:30 -0500 | [diff] [blame] | 104 | * it. |
| 105 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 106 | lli->lli_flags &= ~LLIF_DONE_WRITING; |
| 107 | |
| 108 | wake_up(&lcq->lcq_waitq); |
| 109 | spin_unlock(&lcq->lcq_lock); |
| 110 | } |
| 111 | spin_unlock(&lli->lli_lock); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /** Pack SOM attributes info @opdata for CLOSE, DONE_WRITING rpc. */ |
| 115 | void ll_done_writing_attr(struct inode *inode, struct md_op_data *op_data) |
| 116 | { |
| 117 | struct ll_inode_info *lli = ll_i2info(inode); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 118 | |
| 119 | op_data->op_flags |= MF_SOM_CHANGE; |
| 120 | /* Check if Size-on-MDS attributes are valid. */ |
| 121 | if (lli->lli_flags & LLIF_MDS_SIZE_LOCK) |
James Nunez | 97a075c | 2016-04-27 18:21:01 -0400 | [diff] [blame] | 122 | CERROR("%s: inode "DFID"(flags %u) MDS holds lock on Size-on-MDS attributes\n", |
| 123 | ll_get_fsname(inode->i_sb, NULL, 0), |
| 124 | PFID(ll_inode2fid(inode)), lli->lli_flags); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 125 | |
| 126 | if (!cl_local_size(inode)) { |
| 127 | /* Send Size-on-MDS Attributes if valid. */ |
| 128 | op_data->op_attr.ia_valid |= ATTR_MTIME_SET | ATTR_CTIME_SET | |
| 129 | ATTR_ATIME_SET | ATTR_SIZE | ATTR_BLOCKS; |
| 130 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | /** Closes ioepoch and packs Size-on-MDS attribute if needed into @op_data. */ |
| 134 | void ll_ioepoch_close(struct inode *inode, struct md_op_data *op_data, |
| 135 | struct obd_client_handle **och, unsigned long flags) |
| 136 | { |
| 137 | struct ll_inode_info *lli = ll_i2info(inode); |
John L. Hammond | 8c7b0e1 | 2016-03-30 19:48:47 -0400 | [diff] [blame] | 138 | struct vvp_object *club = cl2vvp(ll_i2info(inode)->lli_clob); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 139 | |
| 140 | spin_lock(&lli->lli_lock); |
John L. Hammond | 8c7b0e1 | 2016-03-30 19:48:47 -0400 | [diff] [blame] | 141 | if (!(list_empty(&club->vob_pending_list))) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 142 | if (!(lli->lli_flags & LLIF_EPOCH_PENDING)) { |
Oleg Drokin | 6e16818 | 2016-02-16 00:46:46 -0500 | [diff] [blame] | 143 | LASSERT(*och); |
| 144 | LASSERT(!lli->lli_pending_och); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 145 | /* Inode is dirty and there is no pending write done |
Oleg Drokin | c0894c6 | 2016-02-24 22:00:30 -0500 | [diff] [blame] | 146 | * request yet, DONE_WRITE is to be sent later. |
| 147 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 148 | lli->lli_flags |= LLIF_EPOCH_PENDING; |
| 149 | lli->lli_pending_och = *och; |
| 150 | spin_unlock(&lli->lli_lock); |
| 151 | |
| 152 | inode = igrab(inode); |
| 153 | LASSERT(inode); |
Julia Lawall | 34e1f2b | 2014-08-30 16:24:55 +0200 | [diff] [blame] | 154 | goto out; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 155 | } |
| 156 | if (flags & LLIF_DONE_WRITING) { |
| 157 | /* Some pages are still dirty, it is early to send |
Masanari Iida | bef31c7 | 2013-09-15 14:38:18 +0900 | [diff] [blame] | 158 | * DONE_WRITE. Wait until all pages will be flushed |
Oleg Drokin | c0894c6 | 2016-02-24 22:00:30 -0500 | [diff] [blame] | 159 | * and try DONE_WRITE again later. |
| 160 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 161 | LASSERT(!(lli->lli_flags & LLIF_DONE_WRITING)); |
| 162 | lli->lli_flags |= LLIF_DONE_WRITING; |
| 163 | spin_unlock(&lli->lli_lock); |
| 164 | |
| 165 | inode = igrab(inode); |
| 166 | LASSERT(inode); |
Julia Lawall | 34e1f2b | 2014-08-30 16:24:55 +0200 | [diff] [blame] | 167 | goto out; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 168 | } |
| 169 | } |
Greg Kroah-Hartman | b0f5aad | 2014-07-12 20:06:04 -0700 | [diff] [blame] | 170 | CDEBUG(D_INODE, "Epoch %llu closed on "DFID"\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 171 | ll_i2info(inode)->lli_ioepoch, PFID(&lli->lli_fid)); |
| 172 | op_data->op_flags |= MF_EPOCH_CLOSE; |
| 173 | |
| 174 | if (flags & LLIF_DONE_WRITING) { |
| 175 | LASSERT(lli->lli_flags & LLIF_SOM_DIRTY); |
| 176 | LASSERT(!(lli->lli_flags & LLIF_DONE_WRITING)); |
| 177 | *och = lli->lli_pending_och; |
| 178 | lli->lli_pending_och = NULL; |
| 179 | lli->lli_flags &= ~LLIF_EPOCH_PENDING; |
| 180 | } else { |
| 181 | /* Pack Size-on-MDS inode attributes only if they has changed */ |
| 182 | if (!(lli->lli_flags & LLIF_SOM_DIRTY)) { |
| 183 | spin_unlock(&lli->lli_lock); |
Julia Lawall | 34e1f2b | 2014-08-30 16:24:55 +0200 | [diff] [blame] | 184 | goto out; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | /* There is a pending DONE_WRITE -- close epoch with no |
Oleg Drokin | c0894c6 | 2016-02-24 22:00:30 -0500 | [diff] [blame] | 188 | * attribute change. |
| 189 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 190 | if (lli->lli_flags & LLIF_EPOCH_PENDING) { |
| 191 | spin_unlock(&lli->lli_lock); |
Julia Lawall | 34e1f2b | 2014-08-30 16:24:55 +0200 | [diff] [blame] | 192 | goto out; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 193 | } |
| 194 | } |
| 195 | |
John L. Hammond | 8c7b0e1 | 2016-03-30 19:48:47 -0400 | [diff] [blame] | 196 | LASSERT(list_empty(&club->vob_pending_list)); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 197 | lli->lli_flags &= ~LLIF_SOM_DIRTY; |
| 198 | spin_unlock(&lli->lli_lock); |
| 199 | ll_done_writing_attr(inode, op_data); |
| 200 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 201 | out: |
| 202 | return; |
| 203 | } |
| 204 | |
| 205 | /** |
| 206 | * Cliens updates SOM attributes on MDS (including llog cookies): |
| 207 | * obd_getattr with no lock and md_setattr. |
| 208 | */ |
| 209 | int ll_som_update(struct inode *inode, struct md_op_data *op_data) |
| 210 | { |
| 211 | struct ll_inode_info *lli = ll_i2info(inode); |
| 212 | struct ptlrpc_request *request = NULL; |
| 213 | __u32 old_flags; |
| 214 | struct obdo *oa; |
| 215 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 216 | |
Oleg Drokin | 6e16818 | 2016-02-16 00:46:46 -0500 | [diff] [blame] | 217 | LASSERT(op_data); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 218 | if (lli->lli_flags & LLIF_MDS_SIZE_LOCK) |
James Nunez | 97a075c | 2016-04-27 18:21:01 -0400 | [diff] [blame] | 219 | CERROR("%s: inode "DFID"(flags %u) MDS holds lock on Size-on-MDS attributes\n", |
| 220 | ll_get_fsname(inode->i_sb, NULL, 0), |
| 221 | PFID(ll_inode2fid(inode)), lli->lli_flags); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 222 | |
Amitoj Kaur Chawla | 21068c4 | 2016-02-26 14:25:09 +0530 | [diff] [blame] | 223 | oa = kmem_cache_zalloc(obdo_cachep, GFP_NOFS); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 224 | if (!oa) { |
| 225 | CERROR("can't allocate memory for Size-on-MDS update.\n"); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 226 | return -ENOMEM; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | old_flags = op_data->op_flags; |
| 230 | op_data->op_flags = MF_SOM_CHANGE; |
| 231 | |
| 232 | /* If inode is already in another epoch, skip getattr from OSTs. */ |
| 233 | if (lli->lli_ioepoch == op_data->op_ioepoch) { |
| 234 | rc = ll_inode_getattr(inode, oa, op_data->op_ioepoch, |
| 235 | old_flags & MF_GETATTR_LOCK); |
| 236 | if (rc) { |
| 237 | oa->o_valid = 0; |
| 238 | if (rc != -ENOENT) |
James Nunez | 97a075c | 2016-04-27 18:21:01 -0400 | [diff] [blame] | 239 | CERROR("%s: inode_getattr failed - unable to send a Size-on-MDS attribute update for inode "DFID": rc = %d\n", |
| 240 | ll_get_fsname(inode->i_sb, NULL, 0), |
| 241 | PFID(ll_inode2fid(inode)), rc); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 242 | } else { |
| 243 | CDEBUG(D_INODE, "Size-on-MDS update on "DFID"\n", |
| 244 | PFID(&lli->lli_fid)); |
| 245 | } |
| 246 | /* Install attributes into op_data. */ |
| 247 | md_from_obdo(op_data, oa, oa->o_valid); |
| 248 | } |
| 249 | |
| 250 | rc = md_setattr(ll_i2sbi(inode)->ll_md_exp, op_data, |
| 251 | NULL, 0, NULL, 0, &request, NULL); |
| 252 | ptlrpc_req_finished(request); |
| 253 | |
Mike Rapoport | 2ba262f | 2015-10-20 12:39:46 +0300 | [diff] [blame] | 254 | kmem_cache_free(obdo_cachep, oa); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 255 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | /** |
| 259 | * Closes the ioepoch and packs all the attributes into @op_data for |
| 260 | * DONE_WRITING rpc. |
| 261 | */ |
| 262 | static void ll_prepare_done_writing(struct inode *inode, |
| 263 | struct md_op_data *op_data, |
| 264 | struct obd_client_handle **och) |
| 265 | { |
| 266 | ll_ioepoch_close(inode, op_data, och, LLIF_DONE_WRITING); |
| 267 | /* If there is no @och, we do not do D_W yet. */ |
Oleg Drokin | 6e16818 | 2016-02-16 00:46:46 -0500 | [diff] [blame] | 268 | if (!*och) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 269 | return; |
| 270 | |
| 271 | ll_pack_inode2opdata(inode, op_data, &(*och)->och_fh); |
| 272 | ll_prep_md_op_data(op_data, inode, NULL, NULL, |
| 273 | 0, 0, LUSTRE_OPC_ANY, NULL); |
| 274 | } |
| 275 | |
| 276 | /** Send a DONE_WRITING rpc. */ |
| 277 | static void ll_done_writing(struct inode *inode) |
| 278 | { |
| 279 | struct obd_client_handle *och = NULL; |
| 280 | struct md_op_data *op_data; |
| 281 | int rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 282 | |
| 283 | LASSERT(exp_connect_som(ll_i2mdexp(inode))); |
| 284 | |
Julia Lawall | 496a51b | 2014-09-18 22:24:02 +0200 | [diff] [blame] | 285 | op_data = kzalloc(sizeof(*op_data), GFP_NOFS); |
Quentin Lambert | 695a066 | 2015-02-12 15:56:07 +0100 | [diff] [blame] | 286 | if (!op_data) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 287 | return; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 288 | |
| 289 | ll_prepare_done_writing(inode, op_data, &och); |
| 290 | /* If there is no @och, we do not do D_W yet. */ |
Oleg Drokin | 6e16818 | 2016-02-16 00:46:46 -0500 | [diff] [blame] | 291 | if (!och) |
Julia Lawall | 34e1f2b | 2014-08-30 16:24:55 +0200 | [diff] [blame] | 292 | goto out; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 293 | |
| 294 | rc = md_done_writing(ll_i2sbi(inode)->ll_md_exp, op_data, NULL); |
Shraddha Barke | d9ec18cf | 2015-09-05 18:58:23 +0530 | [diff] [blame] | 295 | if (rc == -EAGAIN) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 296 | /* MDS has instructed us to obtain Size-on-MDS attribute from |
Oleg Drokin | c0894c6 | 2016-02-24 22:00:30 -0500 | [diff] [blame] | 297 | * OSTs and send setattr to back to MDS. |
| 298 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 299 | rc = ll_som_update(inode, op_data); |
James Nunez | 97a075c | 2016-04-27 18:21:01 -0400 | [diff] [blame] | 300 | else if (rc) { |
| 301 | CERROR("%s: inode "DFID" mdc done_writing failed: rc = %d\n", |
| 302 | ll_get_fsname(inode->i_sb, NULL, 0), |
| 303 | PFID(ll_inode2fid(inode)), rc); |
| 304 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 305 | out: |
| 306 | ll_finish_md_op_data(op_data); |
| 307 | if (och) { |
| 308 | md_clear_open_replay_data(ll_i2sbi(inode)->ll_md_exp, och); |
Julia Lawall | 97903a2 | 2015-04-12 22:55:02 +0200 | [diff] [blame] | 309 | kfree(och); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 310 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | static struct ll_inode_info *ll_close_next_lli(struct ll_close_queue *lcq) |
| 314 | { |
| 315 | struct ll_inode_info *lli = NULL; |
| 316 | |
| 317 | spin_lock(&lcq->lcq_lock); |
| 318 | |
| 319 | if (!list_empty(&lcq->lcq_head)) { |
| 320 | lli = list_entry(lcq->lcq_head.next, struct ll_inode_info, |
Oleg Drokin | e15ba45 | 2016-02-26 01:49:49 -0500 | [diff] [blame] | 321 | lli_close_list); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 322 | list_del_init(&lli->lli_close_list); |
Oleg Drokin | da5ecb4 | 2016-04-01 15:18:01 -0400 | [diff] [blame] | 323 | } else if (atomic_read(&lcq->lcq_stop)) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 324 | lli = ERR_PTR(-EALREADY); |
Oleg Drokin | da5ecb4 | 2016-04-01 15:18:01 -0400 | [diff] [blame] | 325 | } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 326 | |
| 327 | spin_unlock(&lcq->lcq_lock); |
| 328 | return lli; |
| 329 | } |
| 330 | |
| 331 | static int ll_close_thread(void *arg) |
| 332 | { |
| 333 | struct ll_close_queue *lcq = arg; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 334 | |
| 335 | complete(&lcq->lcq_comp); |
| 336 | |
| 337 | while (1) { |
| 338 | struct l_wait_info lwi = { 0 }; |
| 339 | struct ll_inode_info *lli; |
| 340 | struct inode *inode; |
| 341 | |
| 342 | l_wait_event_exclusive(lcq->lcq_waitq, |
| 343 | (lli = ll_close_next_lli(lcq)) != NULL, |
| 344 | &lwi); |
| 345 | if (IS_ERR(lli)) |
| 346 | break; |
| 347 | |
| 348 | inode = ll_info2i(lli); |
James Nunez | 97a075c | 2016-04-27 18:21:01 -0400 | [diff] [blame] | 349 | CDEBUG(D_INFO, "done_writing for inode "DFID"\n", |
| 350 | PFID(ll_inode2fid(inode))); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 351 | ll_done_writing(inode); |
| 352 | iput(inode); |
| 353 | } |
| 354 | |
| 355 | CDEBUG(D_INFO, "ll_close exiting\n"); |
| 356 | complete(&lcq->lcq_comp); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 357 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | int ll_close_thread_start(struct ll_close_queue **lcq_ret) |
| 361 | { |
| 362 | struct ll_close_queue *lcq; |
Greg Kroah-Hartman | 68b636b | 2013-08-04 08:56:42 +0800 | [diff] [blame] | 363 | struct task_struct *task; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 364 | |
| 365 | if (OBD_FAIL_CHECK(OBD_FAIL_LDLM_CLOSE_THREAD)) |
| 366 | return -EINTR; |
| 367 | |
Julia Lawall | 496a51b | 2014-09-18 22:24:02 +0200 | [diff] [blame] | 368 | lcq = kzalloc(sizeof(*lcq), GFP_NOFS); |
| 369 | if (!lcq) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 370 | return -ENOMEM; |
| 371 | |
| 372 | spin_lock_init(&lcq->lcq_lock); |
| 373 | INIT_LIST_HEAD(&lcq->lcq_head); |
| 374 | init_waitqueue_head(&lcq->lcq_waitq); |
| 375 | init_completion(&lcq->lcq_comp); |
| 376 | |
| 377 | task = kthread_run(ll_close_thread, lcq, "ll_close"); |
| 378 | if (IS_ERR(task)) { |
Julia Lawall | 97903a2 | 2015-04-12 22:55:02 +0200 | [diff] [blame] | 379 | kfree(lcq); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 380 | return PTR_ERR(task); |
| 381 | } |
| 382 | |
| 383 | wait_for_completion(&lcq->lcq_comp); |
| 384 | *lcq_ret = lcq; |
| 385 | return 0; |
| 386 | } |
| 387 | |
| 388 | void ll_close_thread_shutdown(struct ll_close_queue *lcq) |
| 389 | { |
| 390 | init_completion(&lcq->lcq_comp); |
| 391 | atomic_inc(&lcq->lcq_stop); |
| 392 | wake_up(&lcq->lcq_waitq); |
| 393 | wait_for_completion(&lcq->lcq_comp); |
Julia Lawall | 97903a2 | 2015-04-12 22:55:02 +0200 | [diff] [blame] | 394 | kfree(lcq); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 395 | } |