Skip to content

Commit 9623e5a

Browse files
committed
Merge branch 'upstream-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jlbec/ocfs2
* 'upstream-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jlbec/ocfs2: ocfs2: Fix a race in o2dlm lockres mastery Ocfs2: Handle deletion of reflinked oprhan inodes correctly. Ocfs2: Journaling i_flags and i_orphaned_slot when adding inode to orphan dir. ocfs2: Clear undo bits when local alloc is freed ocfs2: Init meta_ac properly in ocfs2_create_empty_xattr_block. ocfs2: Fix the update of name_offset when removing xattrs ocfs2: Always try for maximum bits with new local alloc windows ocfs2: set i_mode on disk during acl operations ocfs2: Update i_blocks in reflink operations. ocfs2: Change bg_chain check for ocfs2_validate_gd_parent. [PATCH] Skip check for mandatory locks when unlocking
2 parents 9f32160 + 1474147 commit 9623e5a

11 files changed

Lines changed: 223 additions & 74 deletions

File tree

‎fs/ocfs2/acl.c‎

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
#include "alloc.h"
3131
#include "dlmglue.h"
3232
#include "file.h"
33+
#include "inode.h"
34+
#include "journal.h"
3335
#include "ocfs2_fs.h"
3436

3537
#include "xattr.h"
@@ -165,6 +167,60 @@ static struct posix_acl *ocfs2_get_acl(struct inode *inode, int type)
165167
return acl;
166168
}
167169

170+
/*
171+
* Helper function to set i_mode in memory and disk. Some call paths
172+
* will not have di_bh or a journal handle to pass, in which case it
173+
* will create it's own.
174+
*/
175+
static int ocfs2_acl_set_mode(struct inode *inode, struct buffer_head *di_bh,
176+
handle_t *handle, umode_t new_mode)
177+
{
178+
int ret, commit_handle = 0;
179+
struct ocfs2_dinode *di;
180+
181+
if (di_bh == NULL) {
182+
ret = ocfs2_read_inode_block(inode, &di_bh);
183+
if (ret) {
184+
mlog_errno(ret);
185+
goto out;
186+
}
187+
} else
188+
get_bh(di_bh);
189+
190+
if (handle == NULL) {
191+
handle = ocfs2_start_trans(OCFS2_SB(inode->i_sb),
192+
OCFS2_INODE_UPDATE_CREDITS);
193+
if (IS_ERR(handle)) {
194+
ret = PTR_ERR(handle);
195+
mlog_errno(ret);
196+
goto out_brelse;
197+
}
198+
199+
commit_handle = 1;
200+
}
201+
202+
di = (struct ocfs2_dinode *)di_bh->b_data;
203+
ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), di_bh,
204+
OCFS2_JOURNAL_ACCESS_WRITE);
205+
if (ret) {
206+
mlog_errno(ret);
207+
goto out_commit;
208+
}
209+
210+
inode->i_mode = new_mode;
211+
di->i_mode = cpu_to_le16(inode->i_mode);
212+
213+
ocfs2_journal_dirty(handle, di_bh);
214+
215+
out_commit:
216+
if (commit_handle)
217+
ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle);
218+
out_brelse:
219+
brelse(di_bh);
220+
out:
221+
return ret;
222+
}
223+
168224
/*
169225
* Set the access or default ACL of an inode.
170226
*/
@@ -193,9 +249,14 @@ static int ocfs2_set_acl(handle_t *handle,
193249
if (ret < 0)
194250
return ret;
195251
else {
196-
inode->i_mode = mode;
197252
if (ret == 0)
198253
acl = NULL;
254+
255+
ret = ocfs2_acl_set_mode(inode, di_bh,
256+
handle, mode);
257+
if (ret)
258+
return ret;
259+
199260
}
200261
}
201262
break;
@@ -283,6 +344,7 @@ int ocfs2_init_acl(handle_t *handle,
283344
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
284345
struct posix_acl *acl = NULL;
285346
int ret = 0;
347+
mode_t mode;
286348

287349
if (!S_ISLNK(inode->i_mode)) {
288350
if (osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) {
@@ -291,12 +353,17 @@ int ocfs2_init_acl(handle_t *handle,
291353
if (IS_ERR(acl))
292354
return PTR_ERR(acl);
293355
}
294-
if (!acl)
295-
inode->i_mode &= ~current_umask();
356+
if (!acl) {
357+
mode = inode->i_mode & ~current_umask();
358+
ret = ocfs2_acl_set_mode(inode, di_bh, handle, mode);
359+
if (ret) {
360+
mlog_errno(ret);
361+
goto cleanup;
362+
}
363+
}
296364
}
297365
if ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) && acl) {
298366
struct posix_acl *clone;
299-
mode_t mode;
300367

301368
if (S_ISDIR(inode->i_mode)) {
302369
ret = ocfs2_set_acl(handle, inode, di_bh,
@@ -313,7 +380,7 @@ int ocfs2_init_acl(handle_t *handle,
313380
mode = inode->i_mode;
314381
ret = posix_acl_create_masq(clone, &mode);
315382
if (ret >= 0) {
316-
inode->i_mode = mode;
383+
ret = ocfs2_acl_set_mode(inode, di_bh, handle, mode);
317384
if (ret > 0) {
318385
ret = ocfs2_set_acl(handle, inode,
319386
di_bh, ACL_TYPE_ACCESS,

‎fs/ocfs2/dlm/dlmmaster.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1875,7 +1875,6 @@ int dlm_assert_master_handler(struct o2net_msg *msg, u32 len, void *data,
18751875
ok:
18761876
spin_unlock(&res->spinlock);
18771877
}
1878-
spin_unlock(&dlm->spinlock);
18791878

18801879
// mlog(0, "woo! got an assert_master from node %u!\n",
18811880
// assert->node_idx);
@@ -1926,7 +1925,6 @@ int dlm_assert_master_handler(struct o2net_msg *msg, u32 len, void *data,
19261925
/* master is known, detach if not already detached.
19271926
* ensures that only one assert_master call will happen
19281927
* on this mle. */
1929-
spin_lock(&dlm->spinlock);
19301928
spin_lock(&dlm->master_lock);
19311929

19321930
rr = atomic_read(&mle->mle_refs.refcount);
@@ -1959,14 +1957,14 @@ int dlm_assert_master_handler(struct o2net_msg *msg, u32 len, void *data,
19591957
__dlm_put_mle(mle);
19601958
}
19611959
spin_unlock(&dlm->master_lock);
1962-
spin_unlock(&dlm->spinlock);
19631960
} else if (res) {
19641961
if (res->owner != assert->node_idx) {
19651962
mlog(0, "assert_master from %u, but current "
19661963
"owner is %u (%.*s), no mle\n", assert->node_idx,
19671964
res->owner, namelen, name);
19681965
}
19691966
}
1967+
spin_unlock(&dlm->spinlock);
19701968

19711969
done:
19721970
ret = 0;

‎fs/ocfs2/inode.c‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,21 @@ static int ocfs2_query_inode_wipe(struct inode *inode,
891891
/* Do some basic inode verification... */
892892
di = (struct ocfs2_dinode *) di_bh->b_data;
893893
if (!(di->i_flags & cpu_to_le32(OCFS2_ORPHANED_FL))) {
894+
/*
895+
* Inodes in the orphan dir must have ORPHANED_FL. The only
896+
* inodes that come back out of the orphan dir are reflink
897+
* targets. A reflink target may be moved out of the orphan
898+
* dir between the time we scan the directory and the time we
899+
* process it. This would lead to HAS_REFCOUNT_FL being set but
900+
* ORPHANED_FL not.
901+
*/
902+
if (di->i_dyn_features & cpu_to_le16(OCFS2_HAS_REFCOUNT_FL)) {
903+
mlog(0, "Reflinked inode %llu is no longer orphaned. "
904+
"it shouldn't be deleted\n",
905+
(unsigned long long)oi->ip_blkno);
906+
goto bail;
907+
}
908+
894909
/* for lack of a better error? */
895910
status = -EEXIST;
896911
mlog(ML_ERROR,

‎fs/ocfs2/localalloc.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -872,8 +872,10 @@ static int ocfs2_sync_local_to_main(struct ocfs2_super *osb,
872872
(unsigned long long)la_start_blk,
873873
(unsigned long long)blkno);
874874

875-
status = ocfs2_free_clusters(handle, main_bm_inode,
876-
main_bm_bh, blkno, count);
875+
status = ocfs2_release_clusters(handle,
876+
main_bm_inode,
877+
main_bm_bh, blkno,
878+
count);
877879
if (status < 0) {
878880
mlog_errno(status);
879881
goto bail;
@@ -984,8 +986,7 @@ static int ocfs2_local_alloc_reserve_for_window(struct ocfs2_super *osb,
984986
}
985987

986988
retry_enospc:
987-
(*ac)->ac_bits_wanted = osb->local_alloc_bits;
988-
989+
(*ac)->ac_bits_wanted = osb->local_alloc_default_bits;
989990
status = ocfs2_reserve_cluster_bitmap_bits(osb, *ac);
990991
if (status == -ENOSPC) {
991992
if (ocfs2_recalc_la_window(osb, OCFS2_LA_EVENT_ENOSPC) ==
@@ -1061,6 +1062,7 @@ static int ocfs2_local_alloc_new_window(struct ocfs2_super *osb,
10611062
OCFS2_LA_DISABLED)
10621063
goto bail;
10631064

1065+
ac->ac_bits_wanted = osb->local_alloc_default_bits;
10641066
status = ocfs2_claim_clusters(osb, handle, ac,
10651067
osb->local_alloc_bits,
10661068
&cluster_off,

‎fs/ocfs2/locks.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ int ocfs2_lock(struct file *file, int cmd, struct file_lock *fl)
133133

134134
if (!(fl->fl_flags & FL_POSIX))
135135
return -ENOLCK;
136-
if (__mandatory_lock(inode))
136+
if (__mandatory_lock(inode) && fl->fl_type != F_UNLCK)
137137
return -ENOLCK;
138138

139139
return ocfs2_plock(osb->cconn, OCFS2_I(inode)->ip_blkno, file, cmd, fl);

‎fs/ocfs2/namei.c‎

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static int ocfs2_prepare_orphan_dir(struct ocfs2_super *osb,
8484
static int ocfs2_orphan_add(struct ocfs2_super *osb,
8585
handle_t *handle,
8686
struct inode *inode,
87-
struct ocfs2_dinode *fe,
87+
struct buffer_head *fe_bh,
8888
char *name,
8989
struct ocfs2_dir_lookup_result *lookup,
9090
struct inode *orphan_dir_inode);
@@ -879,7 +879,7 @@ static int ocfs2_unlink(struct inode *dir,
879879
fe = (struct ocfs2_dinode *) fe_bh->b_data;
880880

881881
if (inode_is_unlinkable(inode)) {
882-
status = ocfs2_orphan_add(osb, handle, inode, fe, orphan_name,
882+
status = ocfs2_orphan_add(osb, handle, inode, fe_bh, orphan_name,
883883
&orphan_insert, orphan_dir);
884884
if (status < 0) {
885885
mlog_errno(status);
@@ -1300,7 +1300,7 @@ static int ocfs2_rename(struct inode *old_dir,
13001300
if (S_ISDIR(new_inode->i_mode) ||
13011301
(ocfs2_read_links_count(newfe) == 1)) {
13021302
status = ocfs2_orphan_add(osb, handle, new_inode,
1303-
newfe, orphan_name,
1303+
newfe_bh, orphan_name,
13041304
&orphan_insert, orphan_dir);
13051305
if (status < 0) {
13061306
mlog_errno(status);
@@ -1911,14 +1911,15 @@ static int ocfs2_prepare_orphan_dir(struct ocfs2_super *osb,
19111911
static int ocfs2_orphan_add(struct ocfs2_super *osb,
19121912
handle_t *handle,
19131913
struct inode *inode,
1914-
struct ocfs2_dinode *fe,
1914+
struct buffer_head *fe_bh,
19151915
char *name,
19161916
struct ocfs2_dir_lookup_result *lookup,
19171917
struct inode *orphan_dir_inode)
19181918
{
19191919
struct buffer_head *orphan_dir_bh = NULL;
19201920
int status = 0;
19211921
struct ocfs2_dinode *orphan_fe;
1922+
struct ocfs2_dinode *fe = (struct ocfs2_dinode *) fe_bh->b_data;
19221923

19231924
mlog_entry("(inode->i_ino = %lu)\n", inode->i_ino);
19241925

@@ -1959,13 +1960,30 @@ static int ocfs2_orphan_add(struct ocfs2_super *osb,
19591960
goto leave;
19601961
}
19611962

1963+
/*
1964+
* We're going to journal the change of i_flags and i_orphaned_slot.
1965+
* It's safe anyway, though some callers may duplicate the journaling.
1966+
* Journaling within the func just make the logic look more
1967+
* straightforward.
1968+
*/
1969+
status = ocfs2_journal_access_di(handle,
1970+
INODE_CACHE(inode),
1971+
fe_bh,
1972+
OCFS2_JOURNAL_ACCESS_WRITE);
1973+
if (status < 0) {
1974+
mlog_errno(status);
1975+
goto leave;
1976+
}
1977+
19621978
le32_add_cpu(&fe->i_flags, OCFS2_ORPHANED_FL);
19631979

19641980
/* Record which orphan dir our inode now resides
19651981
* in. delete_inode will use this to determine which orphan
19661982
* dir to lock. */
19671983
fe->i_orphaned_slot = cpu_to_le16(osb->slot_num);
19681984

1985+
ocfs2_journal_dirty(handle, fe_bh);
1986+
19691987
mlog(0, "Inode %llu orphaned in slot %d\n",
19701988
(unsigned long long)OCFS2_I(inode)->ip_blkno, osb->slot_num);
19711989

@@ -2123,7 +2141,7 @@ int ocfs2_create_inode_in_orphan(struct inode *dir,
21232141
}
21242142

21252143
di = (struct ocfs2_dinode *)new_di_bh->b_data;
2126-
status = ocfs2_orphan_add(osb, handle, inode, di, orphan_name,
2144+
status = ocfs2_orphan_add(osb, handle, inode, new_di_bh, orphan_name,
21272145
&orphan_insert, orphan_dir);
21282146
if (status < 0) {
21292147
mlog_errno(status);

‎fs/ocfs2/ocfs2.h‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,8 +763,18 @@ static inline unsigned int ocfs2_megabytes_to_clusters(struct super_block *sb,
763763
return megs << (20 - OCFS2_SB(sb)->s_clustersize_bits);
764764
}
765765

766-
#define ocfs2_set_bit ext2_set_bit
767-
#define ocfs2_clear_bit ext2_clear_bit
766+
static inline void _ocfs2_set_bit(unsigned int bit, unsigned long *bitmap)
767+
{
768+
ext2_set_bit(bit, bitmap);
769+
}
770+
#define ocfs2_set_bit(bit, addr) _ocfs2_set_bit((bit), (unsigned long *)(addr))
771+
772+
static inline void _ocfs2_clear_bit(unsigned int bit, unsigned long *bitmap)
773+
{
774+
ext2_clear_bit(bit, bitmap);
775+
}
776+
#define ocfs2_clear_bit(bit, addr) _ocfs2_clear_bit((bit), (unsigned long *)(addr))
777+
768778
#define ocfs2_test_bit ext2_test_bit
769779
#define ocfs2_find_next_zero_bit ext2_find_next_zero_bit
770780
#define ocfs2_find_next_bit ext2_find_next_bit

‎fs/ocfs2/refcounttree.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4075,6 +4075,7 @@ static int ocfs2_complete_reflink(struct inode *s_inode,
40754075
OCFS2_I(t_inode)->ip_dyn_features = OCFS2_I(s_inode)->ip_dyn_features;
40764076
spin_unlock(&OCFS2_I(t_inode)->ip_lock);
40774077
i_size_write(t_inode, size);
4078+
t_inode->i_blocks = s_inode->i_blocks;
40784079

40794080
di->i_xattr_inline_size = s_di->i_xattr_inline_size;
40804081
di->i_clusters = s_di->i_clusters;

0 commit comments

Comments
 (0)