dchg2000

ocfs2-avoid-getting-dlm-lock-of-the-target-directory.patch

Sep 14th, 2021
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.58 KB | None | 0 0
  1. From c86c3b72f9496876af8106eb2b6882a01e7058c1 Mon Sep 17 00:00:00 2001
  2. From: Gang He <[email protected]>
  3. Date: Tue, 27 Jul 2021 17:45:35 +0800
  4. Subject: [PATCH] ocfs2: avoid getting dlm lock of the target directory
  5. multiple times during reflink process
  6.  
  7. During the reflink process, we should acquire the target directory
  8. inode dlm lock at the beginning, and hold this dlm lock until end
  9. of the function.
  10. With this patch, we avoid dlm lock ping-pong effect when clone
  11. files to the same directory simultaneously from mutiple nodes.
  12. There is a typical user scenario, users regularly back up files
  13. to a specified directory through the reflink feature from the
  14. mutiple nodes.
  15. ---
  16. fs/ocfs2/namei.c | 32 +++++++++++++-------------------
  17. fs/ocfs2/namei.h | 2 ++
  18. fs/ocfs2/refcounttree.c | 15 +++++++++++----
  19. fs/ocfs2/xattr.c | 12 +-----------
  20. fs/ocfs2/xattr.h | 1 +
  21. 5 files changed, 28 insertions(+), 34 deletions(-)
  22.  
  23. diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
  24. index 2c46ff6ba4ea..f8bbb22cc60b 100644
  25. --- a/fs/ocfs2/namei.c
  26. +++ b/fs/ocfs2/namei.c
  27. @@ -2489,6 +2489,7 @@ static int ocfs2_prep_new_orphaned_file(struct inode *dir,
  28. }
  29.  
  30. int ocfs2_create_inode_in_orphan(struct inode *dir,
  31. + struct buffer_head **dir_bh,
  32. int mode,
  33. struct inode **new_inode)
  34. {
  35. @@ -2597,13 +2598,16 @@ int ocfs2_create_inode_in_orphan(struct inode *dir,
  36.  
  37. brelse(new_di_bh);
  38.  
  39. - if (!status)
  40. - *new_inode = inode;
  41. -
  42. ocfs2_free_dir_lookup_result(&orphan_insert);
  43.  
  44. - ocfs2_inode_unlock(dir, 1);
  45. - brelse(parent_di_bh);
  46. + if (!status) {
  47. + *new_inode = inode;
  48. + *dir_bh = parent_di_bh;
  49. + } else {
  50. + ocfs2_inode_unlock(dir, 1);
  51. + brelse(parent_di_bh);
  52. + }
  53. +
  54. return status;
  55. }
  56.  
  57. @@ -2760,11 +2764,11 @@ int ocfs2_del_inode_from_orphan(struct ocfs2_super *osb,
  58. }
  59.  
  60. int ocfs2_mv_orphaned_inode_to_new(struct inode *dir,
  61. + struct buffer_head *dir_bh,
  62. struct inode *inode,
  63. struct dentry *dentry)
  64. {
  65. int status = 0;
  66. - struct buffer_head *parent_di_bh = NULL;
  67. handle_t *handle = NULL;
  68. struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);
  69. struct ocfs2_dinode *dir_di, *di;
  70. @@ -2778,14 +2782,7 @@ int ocfs2_mv_orphaned_inode_to_new(struct inode *dir,
  71. (unsigned long long)OCFS2_I(dir)->ip_blkno,
  72. (unsigned long long)OCFS2_I(inode)->ip_blkno);
  73.  
  74. - status = ocfs2_inode_lock(dir, &parent_di_bh, 1);
  75. - if (status < 0) {
  76. - if (status != -ENOENT)
  77. - mlog_errno(status);
  78. - return status;
  79. - }
  80. -
  81. - dir_di = (struct ocfs2_dinode *) parent_di_bh->b_data;
  82. + dir_di = (struct ocfs2_dinode *) dir_bh->b_data;
  83. if (!dir_di->i_links_count) {
  84. /* can't make a file in a deleted directory. */
  85. status = -ENOENT;
  86. @@ -2798,7 +2795,7 @@ int ocfs2_mv_orphaned_inode_to_new(struct inode *dir,
  87. goto leave;
  88.  
  89. /* get a spot inside the dir. */
  90. - status = ocfs2_prepare_dir_for_insert(osb, dir, parent_di_bh,
  91. + status = ocfs2_prepare_dir_for_insert(osb, dir, dir_bh,
  92. dentry->d_name.name,
  93. dentry->d_name.len, &lookup);
  94. if (status < 0) {
  95. @@ -2862,7 +2859,7 @@ int ocfs2_mv_orphaned_inode_to_new(struct inode *dir,
  96. ocfs2_journal_dirty(handle, di_bh);
  97.  
  98. status = ocfs2_add_entry(handle, dentry, inode,
  99. - OCFS2_I(inode)->ip_blkno, parent_di_bh,
  100. + OCFS2_I(inode)->ip_blkno, dir_bh,
  101. &lookup);
  102. if (status < 0) {
  103. mlog_errno(status);
  104. @@ -2886,10 +2883,7 @@ int ocfs2_mv_orphaned_inode_to_new(struct inode *dir,
  105. iput(orphan_dir_inode);
  106. leave:
  107.  
  108. - ocfs2_inode_unlock(dir, 1);
  109. -
  110. brelse(di_bh);
  111. - brelse(parent_di_bh);
  112. brelse(orphan_dir_bh);
  113.  
  114. ocfs2_free_dir_lookup_result(&lookup);
  115. diff --git a/fs/ocfs2/namei.h b/fs/ocfs2/namei.h
  116. index 9cc891eb874e..03a2c526e2c1 100644
  117. --- a/fs/ocfs2/namei.h
  118. +++ b/fs/ocfs2/namei.h
  119. @@ -24,6 +24,7 @@ int ocfs2_orphan_del(struct ocfs2_super *osb,
  120. struct buffer_head *orphan_dir_bh,
  121. bool dio);
  122. int ocfs2_create_inode_in_orphan(struct inode *dir,
  123. + struct buffer_head **dir_bh,
  124. int mode,
  125. struct inode **new_inode);
  126. int ocfs2_add_inode_to_orphan(struct ocfs2_super *osb,
  127. @@ -32,6 +33,7 @@ int ocfs2_del_inode_from_orphan(struct ocfs2_super *osb,
  128. struct inode *inode, struct buffer_head *di_bh,
  129. int update_isize, loff_t end);
  130. int ocfs2_mv_orphaned_inode_to_new(struct inode *dir,
  131. + struct buffer_head *dir_bh,
  132. struct inode *new_inode,
  133. struct dentry *new_dentry);
  134.  
  135. diff --git a/fs/ocfs2/refcounttree.c b/fs/ocfs2/refcounttree.c
  136. index 7f6355cbb587..a9a0c7c37e8e 100644
  137. --- a/fs/ocfs2/refcounttree.c
  138. +++ b/fs/ocfs2/refcounttree.c
  139. @@ -4250,7 +4250,7 @@ static int ocfs2_reflink(struct dentry *old_dentry, struct inode *dir,
  140. {
  141. int error, had_lock;
  142. struct inode *inode = d_inode(old_dentry);
  143. - struct buffer_head *old_bh = NULL;
  144. + struct buffer_head *old_bh = NULL, *dir_bh = NULL;
  145. struct inode *new_orphan_inode = NULL;
  146. struct ocfs2_lock_holder oh;
  147.  
  148. @@ -4258,7 +4258,7 @@ static int ocfs2_reflink(struct dentry *old_dentry, struct inode *dir,
  149. return -EOPNOTSUPP;
  150.  
  151.  
  152. - error = ocfs2_create_inode_in_orphan(dir, inode->i_mode,
  153. + error = ocfs2_create_inode_in_orphan(dir, &dir_bh, inode->i_mode,
  154. &new_orphan_inode);
  155. if (error) {
  156. mlog_errno(error);
  157. @@ -4304,13 +4304,15 @@ static int ocfs2_reflink(struct dentry *old_dentry, struct inode *dir,
  158.  
  159. /* If the security isn't preserved, we need to re-initialize them. */
  160. if (!preserve) {
  161. - error = ocfs2_init_security_and_acl(dir, new_orphan_inode,
  162. + error = ocfs2_init_security_and_acl(dir, dir_bh,
  163. + new_orphan_inode,
  164. &new_dentry->d_name);
  165. if (error)
  166. mlog_errno(error);
  167. }
  168. if (!error) {
  169. - error = ocfs2_mv_orphaned_inode_to_new(dir, new_orphan_inode,
  170. + error = ocfs2_mv_orphaned_inode_to_new(dir, dir_bh,
  171. + new_orphan_inode,
  172. new_dentry);
  173. if (error)
  174. mlog_errno(error);
  175. @@ -4328,6 +4330,11 @@ static int ocfs2_reflink(struct dentry *old_dentry, struct inode *dir,
  176. iput(new_orphan_inode);
  177. }
  178.  
  179. + if (dir_bh) {
  180. + ocfs2_inode_unlock(dir, 1);
  181. + brelse(dir_bh);
  182. + }
  183. +
  184. return error;
  185. }
  186.  
  187. diff --git a/fs/ocfs2/xattr.c b/fs/ocfs2/xattr.c
  188. index dd784eb0cd7c..3f23e3a5018c 100644
  189. --- a/fs/ocfs2/xattr.c
  190. +++ b/fs/ocfs2/xattr.c
  191. @@ -7203,16 +7203,13 @@ int ocfs2_reflink_xattrs(struct inode *old_inode,
  192. /*
  193. * Initialize security and acl for a already created inode.
  194. * Used for reflink a non-preserve-security file.
  195. - *
  196. - * It uses common api like ocfs2_xattr_set, so the caller
  197. - * must not hold any lock expect i_mutex.
  198. */
  199. int ocfs2_init_security_and_acl(struct inode *dir,
  200. + struct buffer_head *dir_bh,
  201. struct inode *inode,
  202. const struct qstr *qstr)
  203. {
  204. int ret = 0;
  205. - struct buffer_head *dir_bh = NULL;
  206.  
  207. ret = ocfs2_init_security_get(inode, dir, qstr, NULL);
  208. if (ret) {
  209. @@ -7220,17 +7217,10 @@ int ocfs2_init_security_and_acl(struct inode *dir,
  210. goto leave;
  211. }
  212.  
  213. - ret = ocfs2_inode_lock(dir, &dir_bh, 0);
  214. - if (ret) {
  215. - mlog_errno(ret);
  216. - goto leave;
  217. - }
  218. ret = ocfs2_init_acl(NULL, inode, dir, NULL, dir_bh, NULL, NULL);
  219. if (ret)
  220. mlog_errno(ret);
  221.  
  222. - ocfs2_inode_unlock(dir, 0);
  223. - brelse(dir_bh);
  224. leave:
  225. return ret;
  226. }
  227. diff --git a/fs/ocfs2/xattr.h b/fs/ocfs2/xattr.h
  228. index 00308b57f64f..b27fd8ba0019 100644
  229. --- a/fs/ocfs2/xattr.h
  230. +++ b/fs/ocfs2/xattr.h
  231. @@ -83,6 +83,7 @@ int ocfs2_reflink_xattrs(struct inode *old_inode,
  232. struct buffer_head *new_bh,
  233. bool preserve_security);
  234. int ocfs2_init_security_and_acl(struct inode *dir,
  235. + struct buffer_head *dir_bh,
  236. struct inode *inode,
  237. const struct qstr *qstr);
  238. #endif /* OCFS2_XATTR_H */
  239. --
  240. 2.12.3
  241.  
  242.  
Advertisement
Add Comment
Please, Sign In to add comment