Skip to content

Commit c271c5c

Browse files
Sunil MushranMark Fasheh
authored andcommitted
ocfs2: local mounts
This allows users to format an ocfs2 file system with a special flag, OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT. When the file system sees this flag, it will not use any cluster services, nor will it require a cluster configuration, thus acting like a 'local' file system. Signed-off-by: Sunil Mushran <sunil.mushran@oracle.com> Signed-off-by: Mark Fasheh <mark.fasheh@oracle.com>
1 parent c997679 commit c271c5c

File tree

11 files changed

+193
-66
lines changed

11 files changed

+193
-66
lines changed

fs/ocfs2/dlmglue.c

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ static int ocfs2_lock_create(struct ocfs2_super *osb,
770770
int dlm_flags)
771771
{
772772
int ret = 0;
773-
enum dlm_status status;
773+
enum dlm_status status = DLM_NORMAL;
774774
unsigned long flags;
775775

776776
mlog_entry_void();
@@ -1138,6 +1138,7 @@ int ocfs2_rw_lock(struct inode *inode, int write)
11381138
{
11391139
int status, level;
11401140
struct ocfs2_lock_res *lockres;
1141+
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
11411142

11421143
BUG_ON(!inode);
11431144

@@ -1147,6 +1148,9 @@ int ocfs2_rw_lock(struct inode *inode, int write)
11471148
(unsigned long long)OCFS2_I(inode)->ip_blkno,
11481149
write ? "EXMODE" : "PRMODE");
11491150

1151+
if (ocfs2_mount_local(osb))
1152+
return 0;
1153+
11501154
lockres = &OCFS2_I(inode)->ip_rw_lockres;
11511155

11521156
level = write ? LKM_EXMODE : LKM_PRMODE;
@@ -1164,14 +1168,16 @@ void ocfs2_rw_unlock(struct inode *inode, int write)
11641168
{
11651169
int level = write ? LKM_EXMODE : LKM_PRMODE;
11661170
struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_rw_lockres;
1171+
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
11671172

11681173
mlog_entry_void();
11691174

11701175
mlog(0, "inode %llu drop %s RW lock\n",
11711176
(unsigned long long)OCFS2_I(inode)->ip_blkno,
11721177
write ? "EXMODE" : "PRMODE");
11731178

1174-
ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level);
1179+
if (!ocfs2_mount_local(osb))
1180+
ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level);
11751181

11761182
mlog_exit_void();
11771183
}
@@ -1182,6 +1188,7 @@ int ocfs2_data_lock_full(struct inode *inode,
11821188
{
11831189
int status = 0, level;
11841190
struct ocfs2_lock_res *lockres;
1191+
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
11851192

11861193
BUG_ON(!inode);
11871194

@@ -1201,6 +1208,9 @@ int ocfs2_data_lock_full(struct inode *inode,
12011208
goto out;
12021209
}
12031210

1211+
if (ocfs2_mount_local(osb))
1212+
goto out;
1213+
12041214
lockres = &OCFS2_I(inode)->ip_data_lockres;
12051215

12061216
level = write ? LKM_EXMODE : LKM_PRMODE;
@@ -1269,14 +1279,16 @@ void ocfs2_data_unlock(struct inode *inode,
12691279
{
12701280
int level = write ? LKM_EXMODE : LKM_PRMODE;
12711281
struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_data_lockres;
1282+
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
12721283

12731284
mlog_entry_void();
12741285

12751286
mlog(0, "inode %llu drop %s DATA lock\n",
12761287
(unsigned long long)OCFS2_I(inode)->ip_blkno,
12771288
write ? "EXMODE" : "PRMODE");
12781289

1279-
if (!ocfs2_is_hard_readonly(OCFS2_SB(inode->i_sb)))
1290+
if (!ocfs2_is_hard_readonly(OCFS2_SB(inode->i_sb)) &&
1291+
!ocfs2_mount_local(osb))
12801292
ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level);
12811293

12821294
mlog_exit_void();
@@ -1467,8 +1479,9 @@ static int ocfs2_meta_lock_update(struct inode *inode,
14671479
{
14681480
int status = 0;
14691481
struct ocfs2_inode_info *oi = OCFS2_I(inode);
1470-
struct ocfs2_lock_res *lockres;
1482+
struct ocfs2_lock_res *lockres = NULL;
14711483
struct ocfs2_dinode *fe;
1484+
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
14721485

14731486
mlog_entry_void();
14741487

@@ -1483,10 +1496,12 @@ static int ocfs2_meta_lock_update(struct inode *inode,
14831496
}
14841497
spin_unlock(&oi->ip_lock);
14851498

1486-
lockres = &oi->ip_meta_lockres;
1499+
if (!ocfs2_mount_local(osb)) {
1500+
lockres = &oi->ip_meta_lockres;
14871501

1488-
if (!ocfs2_should_refresh_lock_res(lockres))
1489-
goto bail;
1502+
if (!ocfs2_should_refresh_lock_res(lockres))
1503+
goto bail;
1504+
}
14901505

14911506
/* This will discard any caching information we might have had
14921507
* for the inode metadata. */
@@ -1496,7 +1511,7 @@ static int ocfs2_meta_lock_update(struct inode *inode,
14961511
* map (directories, bitmap files, etc) */
14971512
ocfs2_extent_map_trunc(inode, 0);
14981513

1499-
if (ocfs2_meta_lvb_is_trustable(inode, lockres)) {
1514+
if (lockres && ocfs2_meta_lvb_is_trustable(inode, lockres)) {
15001515
mlog(0, "Trusting LVB on inode %llu\n",
15011516
(unsigned long long)oi->ip_blkno);
15021517
ocfs2_refresh_inode_from_lvb(inode);
@@ -1543,7 +1558,8 @@ static int ocfs2_meta_lock_update(struct inode *inode,
15431558

15441559
status = 0;
15451560
bail_refresh:
1546-
ocfs2_complete_lock_res_refresh(lockres, status);
1561+
if (lockres)
1562+
ocfs2_complete_lock_res_refresh(lockres, status);
15471563
bail:
15481564
mlog_exit(status);
15491565
return status;
@@ -1585,7 +1601,7 @@ int ocfs2_meta_lock_full(struct inode *inode,
15851601
int arg_flags)
15861602
{
15871603
int status, level, dlm_flags, acquired;
1588-
struct ocfs2_lock_res *lockres;
1604+
struct ocfs2_lock_res *lockres = NULL;
15891605
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
15901606
struct buffer_head *local_bh = NULL;
15911607

@@ -1607,6 +1623,9 @@ int ocfs2_meta_lock_full(struct inode *inode,
16071623
goto bail;
16081624
}
16091625

1626+
if (ocfs2_mount_local(osb))
1627+
goto local;
1628+
16101629
if (!(arg_flags & OCFS2_META_LOCK_RECOVERY))
16111630
wait_event(osb->recovery_event,
16121631
ocfs2_node_map_is_empty(osb, &osb->recovery_map));
@@ -1636,6 +1655,7 @@ int ocfs2_meta_lock_full(struct inode *inode,
16361655
wait_event(osb->recovery_event,
16371656
ocfs2_node_map_is_empty(osb, &osb->recovery_map));
16381657

1658+
local:
16391659
/*
16401660
* We only see this flag if we're being called from
16411661
* ocfs2_read_locked_inode(). It means we're locking an inode
@@ -1644,7 +1664,8 @@ int ocfs2_meta_lock_full(struct inode *inode,
16441664
*/
16451665
if (inode->i_state & I_NEW) {
16461666
status = 0;
1647-
ocfs2_complete_lock_res_refresh(lockres, 0);
1667+
if (lockres)
1668+
ocfs2_complete_lock_res_refresh(lockres, 0);
16481669
goto bail;
16491670
}
16501671

@@ -1767,14 +1788,16 @@ void ocfs2_meta_unlock(struct inode *inode,
17671788
{
17681789
int level = ex ? LKM_EXMODE : LKM_PRMODE;
17691790
struct ocfs2_lock_res *lockres = &OCFS2_I(inode)->ip_meta_lockres;
1791+
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
17701792

17711793
mlog_entry_void();
17721794

17731795
mlog(0, "inode %llu drop %s META lock\n",
17741796
(unsigned long long)OCFS2_I(inode)->ip_blkno,
17751797
ex ? "EXMODE" : "PRMODE");
17761798

1777-
if (!ocfs2_is_hard_readonly(OCFS2_SB(inode->i_sb)))
1799+
if (!ocfs2_is_hard_readonly(OCFS2_SB(inode->i_sb)) &&
1800+
!ocfs2_mount_local(osb))
17781801
ocfs2_cluster_unlock(OCFS2_SB(inode->i_sb), lockres, level);
17791802

17801803
mlog_exit_void();
@@ -1783,7 +1806,7 @@ void ocfs2_meta_unlock(struct inode *inode,
17831806
int ocfs2_super_lock(struct ocfs2_super *osb,
17841807
int ex)
17851808
{
1786-
int status;
1809+
int status = 0;
17871810
int level = ex ? LKM_EXMODE : LKM_PRMODE;
17881811
struct ocfs2_lock_res *lockres = &osb->osb_super_lockres;
17891812
struct buffer_head *bh;
@@ -1794,6 +1817,9 @@ int ocfs2_super_lock(struct ocfs2_super *osb,
17941817
if (ocfs2_is_hard_readonly(osb))
17951818
return -EROFS;
17961819

1820+
if (ocfs2_mount_local(osb))
1821+
goto bail;
1822+
17971823
status = ocfs2_cluster_lock(osb, lockres, level, 0, 0);
17981824
if (status < 0) {
17991825
mlog_errno(status);
@@ -1832,7 +1858,8 @@ void ocfs2_super_unlock(struct ocfs2_super *osb,
18321858
int level = ex ? LKM_EXMODE : LKM_PRMODE;
18331859
struct ocfs2_lock_res *lockres = &osb->osb_super_lockres;
18341860

1835-
ocfs2_cluster_unlock(osb, lockres, level);
1861+
if (!ocfs2_mount_local(osb))
1862+
ocfs2_cluster_unlock(osb, lockres, level);
18361863
}
18371864

18381865
int ocfs2_rename_lock(struct ocfs2_super *osb)
@@ -1843,6 +1870,9 @@ int ocfs2_rename_lock(struct ocfs2_super *osb)
18431870
if (ocfs2_is_hard_readonly(osb))
18441871
return -EROFS;
18451872

1873+
if (ocfs2_mount_local(osb))
1874+
return 0;
1875+
18461876
status = ocfs2_cluster_lock(osb, lockres, LKM_EXMODE, 0, 0);
18471877
if (status < 0)
18481878
mlog_errno(status);
@@ -1854,7 +1884,8 @@ void ocfs2_rename_unlock(struct ocfs2_super *osb)
18541884
{
18551885
struct ocfs2_lock_res *lockres = &osb->osb_rename_lockres;
18561886

1857-
ocfs2_cluster_unlock(osb, lockres, LKM_EXMODE);
1887+
if (!ocfs2_mount_local(osb))
1888+
ocfs2_cluster_unlock(osb, lockres, LKM_EXMODE);
18581889
}
18591890

18601891
int ocfs2_dentry_lock(struct dentry *dentry, int ex)
@@ -1869,6 +1900,9 @@ int ocfs2_dentry_lock(struct dentry *dentry, int ex)
18691900
if (ocfs2_is_hard_readonly(osb))
18701901
return -EROFS;
18711902

1903+
if (ocfs2_mount_local(osb))
1904+
return 0;
1905+
18721906
ret = ocfs2_cluster_lock(osb, &dl->dl_lockres, level, 0, 0);
18731907
if (ret < 0)
18741908
mlog_errno(ret);
@@ -1882,7 +1916,8 @@ void ocfs2_dentry_unlock(struct dentry *dentry, int ex)
18821916
struct ocfs2_dentry_lock *dl = dentry->d_fsdata;
18831917
struct ocfs2_super *osb = OCFS2_SB(dentry->d_sb);
18841918

1885-
ocfs2_cluster_unlock(osb, &dl->dl_lockres, level);
1919+
if (!ocfs2_mount_local(osb))
1920+
ocfs2_cluster_unlock(osb, &dl->dl_lockres, level);
18861921
}
18871922

18881923
/* Reference counting of the dlm debug structure. We want this because
@@ -2145,12 +2180,15 @@ static void ocfs2_dlm_shutdown_debug(struct ocfs2_super *osb)
21452180

21462181
int ocfs2_dlm_init(struct ocfs2_super *osb)
21472182
{
2148-
int status;
2183+
int status = 0;
21492184
u32 dlm_key;
2150-
struct dlm_ctxt *dlm;
2185+
struct dlm_ctxt *dlm = NULL;
21512186

21522187
mlog_entry_void();
21532188

2189+
if (ocfs2_mount_local(osb))
2190+
goto local;
2191+
21542192
status = ocfs2_dlm_init_debug(osb);
21552193
if (status < 0) {
21562194
mlog_errno(status);
@@ -2178,11 +2216,12 @@ int ocfs2_dlm_init(struct ocfs2_super *osb)
21782216
goto bail;
21792217
}
21802218

2219+
dlm_register_eviction_cb(dlm, &osb->osb_eviction_cb);
2220+
2221+
local:
21812222
ocfs2_super_lock_res_init(&osb->osb_super_lockres, osb);
21822223
ocfs2_rename_lock_res_init(&osb->osb_rename_lockres, osb);
21832224

2184-
dlm_register_eviction_cb(dlm, &osb->osb_eviction_cb);
2185-
21862225
osb->dlm = dlm;
21872226

21882227
status = 0;

fs/ocfs2/heartbeat.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ int ocfs2_register_hb_callbacks(struct ocfs2_super *osb)
154154
{
155155
int status;
156156

157+
if (ocfs2_mount_local(osb))
158+
return 0;
159+
157160
status = o2hb_register_callback(&osb->osb_hb_down);
158161
if (status < 0) {
159162
mlog_errno(status);
@@ -172,6 +175,9 @@ void ocfs2_clear_hb_callbacks(struct ocfs2_super *osb)
172175
{
173176
int status;
174177

178+
if (ocfs2_mount_local(osb))
179+
return;
180+
175181
status = o2hb_unregister_callback(&osb->osb_hb_down);
176182
if (status < 0)
177183
mlog_errno(status);
@@ -186,6 +192,9 @@ void ocfs2_stop_heartbeat(struct ocfs2_super *osb)
186192
int ret;
187193
char *argv[5], *envp[3];
188194

195+
if (ocfs2_mount_local(osb))
196+
return;
197+
189198
if (!osb->uuid_str) {
190199
/* This can happen if we don't get far enough in mount... */
191200
mlog(0, "No UUID with which to stop heartbeat!\n\n");

fs/ocfs2/inode.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,8 @@ static int ocfs2_read_locked_inode(struct inode *inode,
423423
* cluster lock before trusting anything anyway.
424424
*/
425425
can_lock = !(args->fi_flags & OCFS2_FI_FLAG_SYSFILE)
426-
&& !(args->fi_flags & OCFS2_FI_FLAG_NOLOCK);
426+
&& !(args->fi_flags & OCFS2_FI_FLAG_NOLOCK)
427+
&& !ocfs2_mount_local(osb);
427428

428429
/*
429430
* To maintain backwards compatibility with older versions of

fs/ocfs2/journal.c

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ handle_t *ocfs2_start_trans(struct ocfs2_super *osb, int max_buffs)
144144
ocfs2_abort(osb->sb, "Detected aborted journal");
145145
handle = ERR_PTR(-EROFS);
146146
}
147-
} else
148-
atomic_inc(&(osb->journal->j_num_trans));
147+
} else {
148+
if (!ocfs2_mount_local(osb))
149+
atomic_inc(&(osb->journal->j_num_trans));
150+
}
149151

150152
return handle;
151153
}
@@ -507,9 +509,23 @@ void ocfs2_journal_shutdown(struct ocfs2_super *osb)
507509

508510
BUG_ON(atomic_read(&(osb->journal->j_num_trans)) != 0);
509511

510-
status = ocfs2_journal_toggle_dirty(osb, 0);
511-
if (status < 0)
512-
mlog_errno(status);
512+
if (ocfs2_mount_local(osb)) {
513+
journal_lock_updates(journal->j_journal);
514+
status = journal_flush(journal->j_journal);
515+
journal_unlock_updates(journal->j_journal);
516+
if (status < 0)
517+
mlog_errno(status);
518+
}
519+
520+
if (status == 0) {
521+
/*
522+
* Do not toggle if flush was unsuccessful otherwise
523+
* will leave dirty metadata in a "clean" journal
524+
*/
525+
status = ocfs2_journal_toggle_dirty(osb, 0);
526+
if (status < 0)
527+
mlog_errno(status);
528+
}
513529

514530
/* Shutdown the kernel journal system */
515531
journal_destroy(journal->j_journal);
@@ -549,7 +565,7 @@ static void ocfs2_clear_journal_error(struct super_block *sb,
549565
}
550566
}
551567

552-
int ocfs2_journal_load(struct ocfs2_journal *journal)
568+
int ocfs2_journal_load(struct ocfs2_journal *journal, int local)
553569
{
554570
int status = 0;
555571
struct ocfs2_super *osb;
@@ -576,14 +592,18 @@ int ocfs2_journal_load(struct ocfs2_journal *journal)
576592
}
577593

578594
/* Launch the commit thread */
579-
osb->commit_task = kthread_run(ocfs2_commit_thread, osb, "ocfs2cmt");
580-
if (IS_ERR(osb->commit_task)) {
581-
status = PTR_ERR(osb->commit_task);
595+
if (!local) {
596+
osb->commit_task = kthread_run(ocfs2_commit_thread, osb,
597+
"ocfs2cmt");
598+
if (IS_ERR(osb->commit_task)) {
599+
status = PTR_ERR(osb->commit_task);
600+
osb->commit_task = NULL;
601+
mlog(ML_ERROR, "unable to launch ocfs2commit thread, "
602+
"error=%d", status);
603+
goto done;
604+
}
605+
} else
582606
osb->commit_task = NULL;
583-
mlog(ML_ERROR, "unable to launch ocfs2commit thread, error=%d",
584-
status);
585-
goto done;
586-
}
587607

588608
done:
589609
mlog_exit(status);

0 commit comments

Comments
 (0)