hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/fs/ocfs2/namei.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /* -*- mode: c; c-basic-offset: 8; -*-
23 * vim: noexpandtab sw=8 ts=8 sts=0:
34 *
....@@ -19,21 +20,6 @@
1920 * linux/fs/minix/dir.c
2021 *
2122 * Copyright (C) 1991, 1992 Linux Torvalds
22
- *
23
- * This program is free software; you can redistribute it and/or
24
- * modify it under the terms of the GNU General Public
25
- * License as published by the Free Software Foundation; either
26
- * version 2 of the License, or (at your option) any later version.
27
- *
28
- * This program is distributed in the hope that it will be useful,
29
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
30
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31
- * General Public License for more details.
32
- *
33
- * You should have received a copy of the GNU General Public
34
- * License along with this program; if not, write to the
35
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
36
- * Boston, MA 021110-1307, USA.
3723 */
3824
3925 #include <linux/fs.h>
....@@ -245,6 +231,7 @@
245231 handle_t *handle = NULL;
246232 struct ocfs2_super *osb;
247233 struct ocfs2_dinode *dirfe;
234
+ struct ocfs2_dinode *fe = NULL;
248235 struct buffer_head *new_fe_bh = NULL;
249236 struct inode *inode = NULL;
250237 struct ocfs2_alloc_context *inode_ac = NULL;
....@@ -395,6 +382,7 @@
395382 goto leave;
396383 }
397384
385
+ fe = (struct ocfs2_dinode *) new_fe_bh->b_data;
398386 if (S_ISDIR(mode)) {
399387 status = ocfs2_fill_new_dir(osb, handle, dir, inode,
400388 new_fe_bh, data_ac, meta_ac);
....@@ -420,7 +408,7 @@
420408
421409 if (status < 0) {
422410 mlog_errno(status);
423
- goto leave;
411
+ goto roll_back;
424412 }
425413
426414 if (si.enable) {
....@@ -428,7 +416,7 @@
428416 meta_ac, data_ac);
429417 if (status < 0) {
430418 mlog_errno(status);
431
- goto leave;
419
+ goto roll_back;
432420 }
433421 }
434422
....@@ -441,7 +429,7 @@
441429 OCFS2_I(dir)->ip_blkno);
442430 if (status) {
443431 mlog_errno(status);
444
- goto leave;
432
+ goto roll_back;
445433 }
446434
447435 dl = dentry->d_fsdata;
....@@ -451,17 +439,27 @@
451439 &lookup);
452440 if (status < 0) {
453441 mlog_errno(status);
454
- goto leave;
442
+ goto roll_back;
455443 }
456444
457445 insert_inode_hash(inode);
458446 d_instantiate(dentry, inode);
459447 status = 0;
448
+
449
+roll_back:
450
+ if (status < 0 && S_ISDIR(mode)) {
451
+ ocfs2_add_links_count(dirfe, -1);
452
+ drop_nlink(dir);
453
+ }
454
+
460455 leave:
461456 if (status < 0 && did_quota_inode)
462457 dquot_free_inode(inode);
463
- if (handle)
458
+ if (handle) {
459
+ if (status < 0 && fe)
460
+ ocfs2_set_links_count(fe, 0);
464461 ocfs2_commit_trans(osb, handle);
462
+ }
465463
466464 ocfs2_inode_unlock(dir, 1);
467465 if (did_block_signals)
....@@ -600,8 +598,7 @@
600598 mlog_errno(status);
601599 }
602600
603
- oi->i_sync_tid = handle->h_transaction->t_tid;
604
- oi->i_datasync_tid = handle->h_transaction->t_tid;
601
+ ocfs2_update_inode_fsync_trans(handle, inode, 1);
605602
606603 leave:
607604 if (status < 0) {
....@@ -639,18 +636,9 @@
639636 return status;
640637 }
641638
642
- status = __ocfs2_mknod_locked(dir, inode, dev, new_fe_bh,
639
+ return __ocfs2_mknod_locked(dir, inode, dev, new_fe_bh,
643640 parent_fe_bh, handle, inode_ac,
644641 fe_blkno, suballoc_loc, suballoc_bit);
645
- if (status < 0) {
646
- u64 bg_blkno = ocfs2_which_suballoc_group(fe_blkno, suballoc_bit);
647
- int tmp = ocfs2_free_suballoc_bits(handle, inode_ac->ac_inode,
648
- inode_ac->ac_bh, suballoc_bit, bg_blkno, 1);
649
- if (tmp)
650
- mlog_errno(tmp);
651
- }
652
-
653
- return status;
654642 }
655643
656644 static int ocfs2_mkdir(struct inode *dir,
....@@ -2031,8 +2019,11 @@
20312019 ocfs2_clusters_to_bytes(osb->sb, 1));
20322020 if (status < 0 && did_quota_inode)
20332021 dquot_free_inode(inode);
2034
- if (handle)
2022
+ if (handle) {
2023
+ if (status < 0 && fe)
2024
+ ocfs2_set_links_count(fe, 0);
20352025 ocfs2_commit_trans(osb, handle);
2026
+ }
20362027
20372028 ocfs2_inode_unlock(dir, 1);
20382029 if (did_block_signals)
....@@ -2500,14 +2491,13 @@
25002491 struct inode *inode = NULL;
25012492 struct inode *orphan_dir = NULL;
25022493 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);
2503
- struct ocfs2_dinode *di = NULL;
25042494 handle_t *handle = NULL;
25052495 char orphan_name[OCFS2_ORPHAN_NAMELEN + 1];
25062496 struct buffer_head *parent_di_bh = NULL;
25072497 struct buffer_head *new_di_bh = NULL;
25082498 struct ocfs2_alloc_context *inode_ac = NULL;
25092499 struct ocfs2_dir_lookup_result orphan_insert = { NULL, };
2510
- u64 uninitialized_var(di_blkno), suballoc_loc;
2500
+ u64 di_blkno, suballoc_loc;
25112501 u16 suballoc_bit;
25122502
25132503 status = ocfs2_inode_lock(dir, &parent_di_bh, 1);
....@@ -2566,7 +2556,6 @@
25662556 goto leave;
25672557 }
25682558
2569
- di = (struct ocfs2_dinode *)new_di_bh->b_data;
25702559 status = ocfs2_orphan_add(osb, handle, inode, new_di_bh, orphan_name,
25712560 &orphan_insert, orphan_dir, false);
25722561 if (status < 0) {