hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
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>
....@@ -212,6 +198,7 @@
212198 * callers. */
213199 if (S_ISDIR(mode))
214200 set_nlink(inode, 2);
201
+ mode = mode_strip_sgid(dir, mode);
215202 inode_init_owner(inode, dir, mode);
216203 status = dquot_initialize(inode);
217204 if (status)
....@@ -245,6 +232,7 @@
245232 handle_t *handle = NULL;
246233 struct ocfs2_super *osb;
247234 struct ocfs2_dinode *dirfe;
235
+ struct ocfs2_dinode *fe = NULL;
248236 struct buffer_head *new_fe_bh = NULL;
249237 struct inode *inode = NULL;
250238 struct ocfs2_alloc_context *inode_ac = NULL;
....@@ -254,6 +242,7 @@
254242 int want_meta = 0;
255243 int xattr_credits = 0;
256244 struct ocfs2_security_xattr_info si = {
245
+ .name = NULL,
257246 .enable = 1,
258247 };
259248 int did_quota_inode = 0;
....@@ -395,6 +384,7 @@
395384 goto leave;
396385 }
397386
387
+ fe = (struct ocfs2_dinode *) new_fe_bh->b_data;
398388 if (S_ISDIR(mode)) {
399389 status = ocfs2_fill_new_dir(osb, handle, dir, inode,
400390 new_fe_bh, data_ac, meta_ac);
....@@ -420,7 +410,7 @@
420410
421411 if (status < 0) {
422412 mlog_errno(status);
423
- goto leave;
413
+ goto roll_back;
424414 }
425415
426416 if (si.enable) {
....@@ -428,7 +418,7 @@
428418 meta_ac, data_ac);
429419 if (status < 0) {
430420 mlog_errno(status);
431
- goto leave;
421
+ goto roll_back;
432422 }
433423 }
434424
....@@ -441,7 +431,7 @@
441431 OCFS2_I(dir)->ip_blkno);
442432 if (status) {
443433 mlog_errno(status);
444
- goto leave;
434
+ goto roll_back;
445435 }
446436
447437 dl = dentry->d_fsdata;
....@@ -451,17 +441,27 @@
451441 &lookup);
452442 if (status < 0) {
453443 mlog_errno(status);
454
- goto leave;
444
+ goto roll_back;
455445 }
456446
457447 insert_inode_hash(inode);
458448 d_instantiate(dentry, inode);
459449 status = 0;
450
+
451
+roll_back:
452
+ if (status < 0 && S_ISDIR(mode)) {
453
+ ocfs2_add_links_count(dirfe, -1);
454
+ drop_nlink(dir);
455
+ }
456
+
460457 leave:
461458 if (status < 0 && did_quota_inode)
462459 dquot_free_inode(inode);
463
- if (handle)
460
+ if (handle) {
461
+ if (status < 0 && fe)
462
+ ocfs2_set_links_count(fe, 0);
464463 ocfs2_commit_trans(osb, handle);
464
+ }
465465
466466 ocfs2_inode_unlock(dir, 1);
467467 if (did_block_signals)
....@@ -600,8 +600,7 @@
600600 mlog_errno(status);
601601 }
602602
603
- oi->i_sync_tid = handle->h_transaction->t_tid;
604
- oi->i_datasync_tid = handle->h_transaction->t_tid;
603
+ ocfs2_update_inode_fsync_trans(handle, inode, 1);
605604
606605 leave:
607606 if (status < 0) {
....@@ -639,18 +638,9 @@
639638 return status;
640639 }
641640
642
- status = __ocfs2_mknod_locked(dir, inode, dev, new_fe_bh,
641
+ return __ocfs2_mknod_locked(dir, inode, dev, new_fe_bh,
643642 parent_fe_bh, handle, inode_ac,
644643 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;
654644 }
655645
656646 static int ocfs2_mkdir(struct inode *dir,
....@@ -1542,6 +1532,10 @@
15421532 status = ocfs2_add_entry(handle, new_dentry, old_inode,
15431533 OCFS2_I(old_inode)->ip_blkno,
15441534 new_dir_bh, &target_insert);
1535
+ if (status < 0) {
1536
+ mlog_errno(status);
1537
+ goto bail;
1538
+ }
15451539 }
15461540
15471541 old_inode->i_ctime = current_time(old_inode);
....@@ -1812,6 +1806,7 @@
18121806 int want_clusters = 0;
18131807 int xattr_credits = 0;
18141808 struct ocfs2_security_xattr_info si = {
1809
+ .name = NULL,
18151810 .enable = 1,
18161811 };
18171812 int did_quota = 0, did_quota_inode = 0;
....@@ -2031,8 +2026,11 @@
20312026 ocfs2_clusters_to_bytes(osb->sb, 1));
20322027 if (status < 0 && did_quota_inode)
20332028 dquot_free_inode(inode);
2034
- if (handle)
2029
+ if (handle) {
2030
+ if (status < 0 && fe)
2031
+ ocfs2_set_links_count(fe, 0);
20352032 ocfs2_commit_trans(osb, handle);
2033
+ }
20362034
20372035 ocfs2_inode_unlock(dir, 1);
20382036 if (did_block_signals)
....@@ -2500,14 +2498,13 @@
25002498 struct inode *inode = NULL;
25012499 struct inode *orphan_dir = NULL;
25022500 struct ocfs2_super *osb = OCFS2_SB(dir->i_sb);
2503
- struct ocfs2_dinode *di = NULL;
25042501 handle_t *handle = NULL;
25052502 char orphan_name[OCFS2_ORPHAN_NAMELEN + 1];
25062503 struct buffer_head *parent_di_bh = NULL;
25072504 struct buffer_head *new_di_bh = NULL;
25082505 struct ocfs2_alloc_context *inode_ac = NULL;
25092506 struct ocfs2_dir_lookup_result orphan_insert = { NULL, };
2510
- u64 uninitialized_var(di_blkno), suballoc_loc;
2507
+ u64 di_blkno, suballoc_loc;
25112508 u16 suballoc_bit;
25122509
25132510 status = ocfs2_inode_lock(dir, &parent_di_bh, 1);
....@@ -2566,7 +2563,6 @@
25662563 goto leave;
25672564 }
25682565
2569
- di = (struct ocfs2_dinode *)new_di_bh->b_data;
25702566 status = ocfs2_orphan_add(osb, handle, inode, new_di_bh, orphan_name,
25712567 &orphan_insert, orphan_dir, false);
25722568 if (status < 0) {