super.c 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * super.c
  5. *
  6. * load/unload driver, mount/dismount volumes
  7. *
  8. * Copyright (C) 2002, 2004 Oracle. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2 of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public
  21. * License along with this program; if not, write to the
  22. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  23. * Boston, MA 021110-1307, USA.
  24. */
  25. #include <linux/module.h>
  26. #include <linux/fs.h>
  27. #include <linux/types.h>
  28. #include <linux/slab.h>
  29. #include <linux/highmem.h>
  30. #include <linux/init.h>
  31. #include <linux/random.h>
  32. #include <linux/statfs.h>
  33. #include <linux/moduleparam.h>
  34. #include <linux/blkdev.h>
  35. #include <linux/socket.h>
  36. #include <linux/inet.h>
  37. #include <linux/parser.h>
  38. #include <linux/crc32.h>
  39. #include <linux/debugfs.h>
  40. #include <linux/mount.h>
  41. #include <linux/seq_file.h>
  42. #include <linux/quotaops.h>
  43. #include <linux/cleancache.h>
  44. #define CREATE_TRACE_POINTS
  45. #include "ocfs2_trace.h"
  46. #include <cluster/masklog.h>
  47. #include "ocfs2.h"
  48. /* this should be the only file to include a version 1 header */
  49. #include "ocfs1_fs_compat.h"
  50. #include "alloc.h"
  51. #include "aops.h"
  52. #include "blockcheck.h"
  53. #include "dlmglue.h"
  54. #include "export.h"
  55. #include "extent_map.h"
  56. #include "heartbeat.h"
  57. #include "inode.h"
  58. #include "journal.h"
  59. #include "localalloc.h"
  60. #include "namei.h"
  61. #include "slot_map.h"
  62. #include "super.h"
  63. #include "sysfile.h"
  64. #include "uptodate.h"
  65. #include "xattr.h"
  66. #include "quota.h"
  67. #include "refcounttree.h"
  68. #include "suballoc.h"
  69. #include "buffer_head_io.h"
  70. #include "filecheck.h"
  71. static struct kmem_cache *ocfs2_inode_cachep;
  72. struct kmem_cache *ocfs2_dquot_cachep;
  73. struct kmem_cache *ocfs2_qf_chunk_cachep;
  74. static struct dentry *ocfs2_debugfs_root;
  75. MODULE_AUTHOR("Oracle");
  76. MODULE_LICENSE("GPL");
  77. MODULE_DESCRIPTION("OCFS2 cluster file system");
  78. struct mount_options
  79. {
  80. unsigned long commit_interval;
  81. unsigned long mount_opt;
  82. unsigned int atime_quantum;
  83. signed short slot;
  84. int localalloc_opt;
  85. unsigned int resv_level;
  86. int dir_resv_level;
  87. char cluster_stack[OCFS2_STACK_LABEL_LEN + 1];
  88. };
  89. static int ocfs2_parse_options(struct super_block *sb, char *options,
  90. struct mount_options *mopt,
  91. int is_remount);
  92. static int ocfs2_check_set_options(struct super_block *sb,
  93. struct mount_options *options);
  94. static int ocfs2_show_options(struct seq_file *s, struct dentry *root);
  95. static void ocfs2_put_super(struct super_block *sb);
  96. static int ocfs2_mount_volume(struct super_block *sb);
  97. static int ocfs2_remount(struct super_block *sb, int *flags, char *data);
  98. static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err);
  99. static int ocfs2_initialize_mem_caches(void);
  100. static void ocfs2_free_mem_caches(void);
  101. static void ocfs2_delete_osb(struct ocfs2_super *osb);
  102. static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf);
  103. static int ocfs2_sync_fs(struct super_block *sb, int wait);
  104. static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb);
  105. static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb);
  106. static void ocfs2_release_system_inodes(struct ocfs2_super *osb);
  107. static int ocfs2_check_volume(struct ocfs2_super *osb);
  108. static int ocfs2_verify_volume(struct ocfs2_dinode *di,
  109. struct buffer_head *bh,
  110. u32 sectsize,
  111. struct ocfs2_blockcheck_stats *stats);
  112. static int ocfs2_initialize_super(struct super_block *sb,
  113. struct buffer_head *bh,
  114. int sector_size,
  115. struct ocfs2_blockcheck_stats *stats);
  116. static int ocfs2_get_sector(struct super_block *sb,
  117. struct buffer_head **bh,
  118. int block,
  119. int sect_size);
  120. static struct inode *ocfs2_alloc_inode(struct super_block *sb);
  121. static void ocfs2_destroy_inode(struct inode *inode);
  122. static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend);
  123. static int ocfs2_enable_quotas(struct ocfs2_super *osb);
  124. static void ocfs2_disable_quotas(struct ocfs2_super *osb);
  125. static struct dquot **ocfs2_get_dquots(struct inode *inode)
  126. {
  127. return OCFS2_I(inode)->i_dquot;
  128. }
  129. static const struct super_operations ocfs2_sops = {
  130. .statfs = ocfs2_statfs,
  131. .alloc_inode = ocfs2_alloc_inode,
  132. .destroy_inode = ocfs2_destroy_inode,
  133. .drop_inode = ocfs2_drop_inode,
  134. .evict_inode = ocfs2_evict_inode,
  135. .sync_fs = ocfs2_sync_fs,
  136. .put_super = ocfs2_put_super,
  137. .remount_fs = ocfs2_remount,
  138. .show_options = ocfs2_show_options,
  139. .quota_read = ocfs2_quota_read,
  140. .quota_write = ocfs2_quota_write,
  141. .get_dquots = ocfs2_get_dquots,
  142. };
  143. enum {
  144. Opt_barrier,
  145. Opt_err_panic,
  146. Opt_err_ro,
  147. Opt_intr,
  148. Opt_nointr,
  149. Opt_hb_none,
  150. Opt_hb_local,
  151. Opt_hb_global,
  152. Opt_data_ordered,
  153. Opt_data_writeback,
  154. Opt_atime_quantum,
  155. Opt_slot,
  156. Opt_commit,
  157. Opt_localalloc,
  158. Opt_localflocks,
  159. Opt_stack,
  160. Opt_user_xattr,
  161. Opt_nouser_xattr,
  162. Opt_inode64,
  163. Opt_acl,
  164. Opt_noacl,
  165. Opt_usrquota,
  166. Opt_grpquota,
  167. Opt_coherency_buffered,
  168. Opt_coherency_full,
  169. Opt_resv_level,
  170. Opt_dir_resv_level,
  171. Opt_journal_async_commit,
  172. Opt_err_cont,
  173. Opt_err,
  174. };
  175. static const match_table_t tokens = {
  176. {Opt_barrier, "barrier=%u"},
  177. {Opt_err_panic, "errors=panic"},
  178. {Opt_err_ro, "errors=remount-ro"},
  179. {Opt_intr, "intr"},
  180. {Opt_nointr, "nointr"},
  181. {Opt_hb_none, OCFS2_HB_NONE},
  182. {Opt_hb_local, OCFS2_HB_LOCAL},
  183. {Opt_hb_global, OCFS2_HB_GLOBAL},
  184. {Opt_data_ordered, "data=ordered"},
  185. {Opt_data_writeback, "data=writeback"},
  186. {Opt_atime_quantum, "atime_quantum=%u"},
  187. {Opt_slot, "preferred_slot=%u"},
  188. {Opt_commit, "commit=%u"},
  189. {Opt_localalloc, "localalloc=%d"},
  190. {Opt_localflocks, "localflocks"},
  191. {Opt_stack, "cluster_stack=%s"},
  192. {Opt_user_xattr, "user_xattr"},
  193. {Opt_nouser_xattr, "nouser_xattr"},
  194. {Opt_inode64, "inode64"},
  195. {Opt_acl, "acl"},
  196. {Opt_noacl, "noacl"},
  197. {Opt_usrquota, "usrquota"},
  198. {Opt_grpquota, "grpquota"},
  199. {Opt_coherency_buffered, "coherency=buffered"},
  200. {Opt_coherency_full, "coherency=full"},
  201. {Opt_resv_level, "resv_level=%u"},
  202. {Opt_dir_resv_level, "dir_resv_level=%u"},
  203. {Opt_journal_async_commit, "journal_async_commit"},
  204. {Opt_err_cont, "errors=continue"},
  205. {Opt_err, NULL}
  206. };
  207. #ifdef CONFIG_DEBUG_FS
  208. static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
  209. {
  210. struct ocfs2_cluster_connection *cconn = osb->cconn;
  211. struct ocfs2_recovery_map *rm = osb->recovery_map;
  212. struct ocfs2_orphan_scan *os = &osb->osb_orphan_scan;
  213. int i, out = 0;
  214. unsigned long flags;
  215. out += snprintf(buf + out, len - out,
  216. "%10s => Id: %-s Uuid: %-s Gen: 0x%X Label: %-s\n",
  217. "Device", osb->dev_str, osb->uuid_str,
  218. osb->fs_generation, osb->vol_label);
  219. out += snprintf(buf + out, len - out,
  220. "%10s => State: %d Flags: 0x%lX\n", "Volume",
  221. atomic_read(&osb->vol_state), osb->osb_flags);
  222. out += snprintf(buf + out, len - out,
  223. "%10s => Block: %lu Cluster: %d\n", "Sizes",
  224. osb->sb->s_blocksize, osb->s_clustersize);
  225. out += snprintf(buf + out, len - out,
  226. "%10s => Compat: 0x%X Incompat: 0x%X "
  227. "ROcompat: 0x%X\n",
  228. "Features", osb->s_feature_compat,
  229. osb->s_feature_incompat, osb->s_feature_ro_compat);
  230. out += snprintf(buf + out, len - out,
  231. "%10s => Opts: 0x%lX AtimeQuanta: %u\n", "Mount",
  232. osb->s_mount_opt, osb->s_atime_quantum);
  233. if (cconn) {
  234. out += snprintf(buf + out, len - out,
  235. "%10s => Stack: %s Name: %*s "
  236. "Version: %d.%d\n", "Cluster",
  237. (*osb->osb_cluster_stack == '\0' ?
  238. "o2cb" : osb->osb_cluster_stack),
  239. cconn->cc_namelen, cconn->cc_name,
  240. cconn->cc_version.pv_major,
  241. cconn->cc_version.pv_minor);
  242. }
  243. spin_lock_irqsave(&osb->dc_task_lock, flags);
  244. out += snprintf(buf + out, len - out,
  245. "%10s => Pid: %d Count: %lu WakeSeq: %lu "
  246. "WorkSeq: %lu\n", "DownCnvt",
  247. (osb->dc_task ? task_pid_nr(osb->dc_task) : -1),
  248. osb->blocked_lock_count, osb->dc_wake_sequence,
  249. osb->dc_work_sequence);
  250. spin_unlock_irqrestore(&osb->dc_task_lock, flags);
  251. spin_lock(&osb->osb_lock);
  252. out += snprintf(buf + out, len - out, "%10s => Pid: %d Nodes:",
  253. "Recovery",
  254. (osb->recovery_thread_task ?
  255. task_pid_nr(osb->recovery_thread_task) : -1));
  256. if (rm->rm_used == 0)
  257. out += snprintf(buf + out, len - out, " None\n");
  258. else {
  259. for (i = 0; i < rm->rm_used; i++)
  260. out += snprintf(buf + out, len - out, " %d",
  261. rm->rm_entries[i]);
  262. out += snprintf(buf + out, len - out, "\n");
  263. }
  264. spin_unlock(&osb->osb_lock);
  265. out += snprintf(buf + out, len - out,
  266. "%10s => Pid: %d Interval: %lu\n", "Commit",
  267. (osb->commit_task ? task_pid_nr(osb->commit_task) : -1),
  268. osb->osb_commit_interval);
  269. out += snprintf(buf + out, len - out,
  270. "%10s => State: %d TxnId: %lu NumTxns: %d\n",
  271. "Journal", osb->journal->j_state,
  272. osb->journal->j_trans_id,
  273. atomic_read(&osb->journal->j_num_trans));
  274. out += snprintf(buf + out, len - out,
  275. "%10s => GlobalAllocs: %d LocalAllocs: %d "
  276. "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
  277. "Stats",
  278. atomic_read(&osb->alloc_stats.bitmap_data),
  279. atomic_read(&osb->alloc_stats.local_data),
  280. atomic_read(&osb->alloc_stats.bg_allocs),
  281. atomic_read(&osb->alloc_stats.moves),
  282. atomic_read(&osb->alloc_stats.bg_extends));
  283. out += snprintf(buf + out, len - out,
  284. "%10s => State: %u Descriptor: %llu Size: %u bits "
  285. "Default: %u bits\n",
  286. "LocalAlloc", osb->local_alloc_state,
  287. (unsigned long long)osb->la_last_gd,
  288. osb->local_alloc_bits, osb->local_alloc_default_bits);
  289. spin_lock(&osb->osb_lock);
  290. out += snprintf(buf + out, len - out,
  291. "%10s => InodeSlot: %d StolenInodes: %d, "
  292. "MetaSlot: %d StolenMeta: %d\n", "Steal",
  293. osb->s_inode_steal_slot,
  294. atomic_read(&osb->s_num_inodes_stolen),
  295. osb->s_meta_steal_slot,
  296. atomic_read(&osb->s_num_meta_stolen));
  297. spin_unlock(&osb->osb_lock);
  298. out += snprintf(buf + out, len - out, "OrphanScan => ");
  299. out += snprintf(buf + out, len - out, "Local: %u Global: %u ",
  300. os->os_count, os->os_seqno);
  301. out += snprintf(buf + out, len - out, " Last Scan: ");
  302. if (atomic_read(&os->os_state) == ORPHAN_SCAN_INACTIVE)
  303. out += snprintf(buf + out, len - out, "Disabled\n");
  304. else
  305. out += snprintf(buf + out, len - out, "%lu seconds ago\n",
  306. (unsigned long)(ktime_get_seconds() - os->os_scantime));
  307. out += snprintf(buf + out, len - out, "%10s => %3s %10s\n",
  308. "Slots", "Num", "RecoGen");
  309. for (i = 0; i < osb->max_slots; ++i) {
  310. out += snprintf(buf + out, len - out,
  311. "%10s %c %3d %10d\n",
  312. " ",
  313. (i == osb->slot_num ? '*' : ' '),
  314. i, osb->slot_recovery_generations[i]);
  315. }
  316. return out;
  317. }
  318. static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
  319. {
  320. struct ocfs2_super *osb = inode->i_private;
  321. char *buf = NULL;
  322. buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  323. if (!buf)
  324. goto bail;
  325. i_size_write(inode, ocfs2_osb_dump(osb, buf, PAGE_SIZE));
  326. file->private_data = buf;
  327. return 0;
  328. bail:
  329. return -ENOMEM;
  330. }
  331. static int ocfs2_debug_release(struct inode *inode, struct file *file)
  332. {
  333. kfree(file->private_data);
  334. return 0;
  335. }
  336. static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
  337. size_t nbytes, loff_t *ppos)
  338. {
  339. return simple_read_from_buffer(buf, nbytes, ppos, file->private_data,
  340. i_size_read(file->f_mapping->host));
  341. }
  342. #else
  343. static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
  344. {
  345. return 0;
  346. }
  347. static int ocfs2_debug_release(struct inode *inode, struct file *file)
  348. {
  349. return 0;
  350. }
  351. static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
  352. size_t nbytes, loff_t *ppos)
  353. {
  354. return 0;
  355. }
  356. #endif /* CONFIG_DEBUG_FS */
  357. static const struct file_operations ocfs2_osb_debug_fops = {
  358. .open = ocfs2_osb_debug_open,
  359. .release = ocfs2_debug_release,
  360. .read = ocfs2_debug_read,
  361. .llseek = generic_file_llseek,
  362. };
  363. static int ocfs2_sync_fs(struct super_block *sb, int wait)
  364. {
  365. int status;
  366. tid_t target;
  367. struct ocfs2_super *osb = OCFS2_SB(sb);
  368. if (ocfs2_is_hard_readonly(osb))
  369. return -EROFS;
  370. if (wait) {
  371. status = ocfs2_flush_truncate_log(osb);
  372. if (status < 0)
  373. mlog_errno(status);
  374. } else {
  375. ocfs2_schedule_truncate_log_flush(osb, 0);
  376. }
  377. if (jbd2_journal_start_commit(OCFS2_SB(sb)->journal->j_journal,
  378. &target)) {
  379. if (wait)
  380. jbd2_log_wait_commit(OCFS2_SB(sb)->journal->j_journal,
  381. target);
  382. }
  383. return 0;
  384. }
  385. static int ocfs2_need_system_inode(struct ocfs2_super *osb, int ino)
  386. {
  387. if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_USRQUOTA)
  388. && (ino == USER_QUOTA_SYSTEM_INODE
  389. || ino == LOCAL_USER_QUOTA_SYSTEM_INODE))
  390. return 0;
  391. if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
  392. && (ino == GROUP_QUOTA_SYSTEM_INODE
  393. || ino == LOCAL_GROUP_QUOTA_SYSTEM_INODE))
  394. return 0;
  395. return 1;
  396. }
  397. static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb)
  398. {
  399. struct inode *new = NULL;
  400. int status = 0;
  401. int i;
  402. new = ocfs2_iget(osb, osb->root_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
  403. if (IS_ERR(new)) {
  404. status = PTR_ERR(new);
  405. mlog_errno(status);
  406. goto bail;
  407. }
  408. osb->root_inode = new;
  409. new = ocfs2_iget(osb, osb->system_dir_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
  410. if (IS_ERR(new)) {
  411. status = PTR_ERR(new);
  412. mlog_errno(status);
  413. goto bail;
  414. }
  415. osb->sys_root_inode = new;
  416. for (i = OCFS2_FIRST_ONLINE_SYSTEM_INODE;
  417. i <= OCFS2_LAST_GLOBAL_SYSTEM_INODE; i++) {
  418. if (!ocfs2_need_system_inode(osb, i))
  419. continue;
  420. new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
  421. if (!new) {
  422. ocfs2_release_system_inodes(osb);
  423. status = -EINVAL;
  424. mlog_errno(status);
  425. /* FIXME: Should ERROR_RO_FS */
  426. mlog(ML_ERROR, "Unable to load system inode %d, "
  427. "possibly corrupt fs?", i);
  428. goto bail;
  429. }
  430. // the array now has one ref, so drop this one
  431. iput(new);
  432. }
  433. bail:
  434. if (status)
  435. mlog_errno(status);
  436. return status;
  437. }
  438. static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb)
  439. {
  440. struct inode *new = NULL;
  441. int status = 0;
  442. int i;
  443. for (i = OCFS2_LAST_GLOBAL_SYSTEM_INODE + 1;
  444. i < NUM_SYSTEM_INODES;
  445. i++) {
  446. if (!ocfs2_need_system_inode(osb, i))
  447. continue;
  448. new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
  449. if (!new) {
  450. ocfs2_release_system_inodes(osb);
  451. status = -EINVAL;
  452. mlog(ML_ERROR, "status=%d, sysfile=%d, slot=%d\n",
  453. status, i, osb->slot_num);
  454. goto bail;
  455. }
  456. /* the array now has one ref, so drop this one */
  457. iput(new);
  458. }
  459. bail:
  460. if (status)
  461. mlog_errno(status);
  462. return status;
  463. }
  464. static void ocfs2_release_system_inodes(struct ocfs2_super *osb)
  465. {
  466. int i;
  467. struct inode *inode;
  468. for (i = 0; i < NUM_GLOBAL_SYSTEM_INODES; i++) {
  469. inode = osb->global_system_inodes[i];
  470. if (inode) {
  471. iput(inode);
  472. osb->global_system_inodes[i] = NULL;
  473. }
  474. }
  475. inode = osb->sys_root_inode;
  476. if (inode) {
  477. iput(inode);
  478. osb->sys_root_inode = NULL;
  479. }
  480. inode = osb->root_inode;
  481. if (inode) {
  482. iput(inode);
  483. osb->root_inode = NULL;
  484. }
  485. if (!osb->local_system_inodes)
  486. return;
  487. for (i = 0; i < NUM_LOCAL_SYSTEM_INODES * osb->max_slots; i++) {
  488. if (osb->local_system_inodes[i]) {
  489. iput(osb->local_system_inodes[i]);
  490. osb->local_system_inodes[i] = NULL;
  491. }
  492. }
  493. kfree(osb->local_system_inodes);
  494. osb->local_system_inodes = NULL;
  495. }
  496. /* We're allocating fs objects, use GFP_NOFS */
  497. static struct inode *ocfs2_alloc_inode(struct super_block *sb)
  498. {
  499. struct ocfs2_inode_info *oi;
  500. oi = kmem_cache_alloc(ocfs2_inode_cachep, GFP_NOFS);
  501. if (!oi)
  502. return NULL;
  503. oi->i_sync_tid = 0;
  504. oi->i_datasync_tid = 0;
  505. memset(&oi->i_dquot, 0, sizeof(oi->i_dquot));
  506. jbd2_journal_init_jbd_inode(&oi->ip_jinode, &oi->vfs_inode);
  507. return &oi->vfs_inode;
  508. }
  509. static void ocfs2_i_callback(struct rcu_head *head)
  510. {
  511. struct inode *inode = container_of(head, struct inode, i_rcu);
  512. kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode));
  513. }
  514. static void ocfs2_destroy_inode(struct inode *inode)
  515. {
  516. call_rcu(&inode->i_rcu, ocfs2_i_callback);
  517. }
  518. static unsigned long long ocfs2_max_file_offset(unsigned int bbits,
  519. unsigned int cbits)
  520. {
  521. unsigned int bytes = 1 << cbits;
  522. unsigned int trim = bytes;
  523. unsigned int bitshift = 32;
  524. /*
  525. * i_size and all block offsets in ocfs2 are always 64 bits
  526. * wide. i_clusters is 32 bits, in cluster-sized units. So on
  527. * 64 bit platforms, cluster size will be the limiting factor.
  528. */
  529. #if BITS_PER_LONG == 32
  530. # if defined(CONFIG_LBDAF)
  531. BUILD_BUG_ON(sizeof(sector_t) != 8);
  532. /*
  533. * We might be limited by page cache size.
  534. */
  535. if (bytes > PAGE_SIZE) {
  536. bytes = PAGE_SIZE;
  537. trim = 1;
  538. /*
  539. * Shift by 31 here so that we don't get larger than
  540. * MAX_LFS_FILESIZE
  541. */
  542. bitshift = 31;
  543. }
  544. # else
  545. /*
  546. * We are limited by the size of sector_t. Use block size, as
  547. * that's what we expose to the VFS.
  548. */
  549. bytes = 1 << bbits;
  550. trim = 1;
  551. bitshift = 31;
  552. # endif
  553. #endif
  554. /*
  555. * Trim by a whole cluster when we can actually approach the
  556. * on-disk limits. Otherwise we can overflow i_clusters when
  557. * an extent start is at the max offset.
  558. */
  559. return (((unsigned long long)bytes) << bitshift) - trim;
  560. }
  561. static int ocfs2_remount(struct super_block *sb, int *flags, char *data)
  562. {
  563. int incompat_features;
  564. int ret = 0;
  565. struct mount_options parsed_options;
  566. struct ocfs2_super *osb = OCFS2_SB(sb);
  567. u32 tmp;
  568. sync_filesystem(sb);
  569. if (!ocfs2_parse_options(sb, data, &parsed_options, 1) ||
  570. !ocfs2_check_set_options(sb, &parsed_options)) {
  571. ret = -EINVAL;
  572. goto out;
  573. }
  574. tmp = OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL |
  575. OCFS2_MOUNT_HB_NONE;
  576. if ((osb->s_mount_opt & tmp) != (parsed_options.mount_opt & tmp)) {
  577. ret = -EINVAL;
  578. mlog(ML_ERROR, "Cannot change heartbeat mode on remount\n");
  579. goto out;
  580. }
  581. if ((osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK) !=
  582. (parsed_options.mount_opt & OCFS2_MOUNT_DATA_WRITEBACK)) {
  583. ret = -EINVAL;
  584. mlog(ML_ERROR, "Cannot change data mode on remount\n");
  585. goto out;
  586. }
  587. /* Probably don't want this on remount; it might
  588. * mess with other nodes */
  589. if (!(osb->s_mount_opt & OCFS2_MOUNT_INODE64) &&
  590. (parsed_options.mount_opt & OCFS2_MOUNT_INODE64)) {
  591. ret = -EINVAL;
  592. mlog(ML_ERROR, "Cannot enable inode64 on remount\n");
  593. goto out;
  594. }
  595. /* We're going to/from readonly mode. */
  596. if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
  597. /* Disable quota accounting before remounting RO */
  598. if (*flags & MS_RDONLY) {
  599. ret = ocfs2_susp_quotas(osb, 0);
  600. if (ret < 0)
  601. goto out;
  602. }
  603. /* Lock here so the check of HARD_RO and the potential
  604. * setting of SOFT_RO is atomic. */
  605. spin_lock(&osb->osb_lock);
  606. if (osb->osb_flags & OCFS2_OSB_HARD_RO) {
  607. mlog(ML_ERROR, "Remount on readonly device is forbidden.\n");
  608. ret = -EROFS;
  609. goto unlock_osb;
  610. }
  611. if (*flags & MS_RDONLY) {
  612. sb->s_flags |= MS_RDONLY;
  613. osb->osb_flags |= OCFS2_OSB_SOFT_RO;
  614. } else {
  615. if (osb->osb_flags & OCFS2_OSB_ERROR_FS) {
  616. mlog(ML_ERROR, "Cannot remount RDWR "
  617. "filesystem due to previous errors.\n");
  618. ret = -EROFS;
  619. goto unlock_osb;
  620. }
  621. incompat_features = OCFS2_HAS_RO_COMPAT_FEATURE(sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP);
  622. if (incompat_features) {
  623. mlog(ML_ERROR, "Cannot remount RDWR because "
  624. "of unsupported optional features "
  625. "(%x).\n", incompat_features);
  626. ret = -EINVAL;
  627. goto unlock_osb;
  628. }
  629. sb->s_flags &= ~MS_RDONLY;
  630. osb->osb_flags &= ~OCFS2_OSB_SOFT_RO;
  631. }
  632. trace_ocfs2_remount(sb->s_flags, osb->osb_flags, *flags);
  633. unlock_osb:
  634. spin_unlock(&osb->osb_lock);
  635. /* Enable quota accounting after remounting RW */
  636. if (!ret && !(*flags & MS_RDONLY)) {
  637. if (sb_any_quota_suspended(sb))
  638. ret = ocfs2_susp_quotas(osb, 1);
  639. else
  640. ret = ocfs2_enable_quotas(osb);
  641. if (ret < 0) {
  642. /* Return back changes... */
  643. spin_lock(&osb->osb_lock);
  644. sb->s_flags |= MS_RDONLY;
  645. osb->osb_flags |= OCFS2_OSB_SOFT_RO;
  646. spin_unlock(&osb->osb_lock);
  647. goto out;
  648. }
  649. }
  650. }
  651. if (!ret) {
  652. /* Only save off the new mount options in case of a successful
  653. * remount. */
  654. osb->s_mount_opt = parsed_options.mount_opt;
  655. osb->s_atime_quantum = parsed_options.atime_quantum;
  656. osb->preferred_slot = parsed_options.slot;
  657. if (parsed_options.commit_interval)
  658. osb->osb_commit_interval = parsed_options.commit_interval;
  659. if (!ocfs2_is_hard_readonly(osb))
  660. ocfs2_set_journal_params(osb);
  661. sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
  662. ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ?
  663. MS_POSIXACL : 0);
  664. }
  665. out:
  666. return ret;
  667. }
  668. static int ocfs2_sb_probe(struct super_block *sb,
  669. struct buffer_head **bh,
  670. int *sector_size,
  671. struct ocfs2_blockcheck_stats *stats)
  672. {
  673. int status, tmpstat;
  674. struct ocfs1_vol_disk_hdr *hdr;
  675. struct ocfs2_dinode *di;
  676. int blksize;
  677. *bh = NULL;
  678. /* may be > 512 */
  679. *sector_size = bdev_logical_block_size(sb->s_bdev);
  680. if (*sector_size > OCFS2_MAX_BLOCKSIZE) {
  681. mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n",
  682. *sector_size, OCFS2_MAX_BLOCKSIZE);
  683. status = -EINVAL;
  684. goto bail;
  685. }
  686. /* Can this really happen? */
  687. if (*sector_size < OCFS2_MIN_BLOCKSIZE)
  688. *sector_size = OCFS2_MIN_BLOCKSIZE;
  689. /* check block zero for old format */
  690. status = ocfs2_get_sector(sb, bh, 0, *sector_size);
  691. if (status < 0) {
  692. mlog_errno(status);
  693. goto bail;
  694. }
  695. hdr = (struct ocfs1_vol_disk_hdr *) (*bh)->b_data;
  696. if (hdr->major_version == OCFS1_MAJOR_VERSION) {
  697. mlog(ML_ERROR, "incompatible version: %u.%u\n",
  698. hdr->major_version, hdr->minor_version);
  699. status = -EINVAL;
  700. }
  701. if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE,
  702. strlen(OCFS1_VOLUME_SIGNATURE)) == 0) {
  703. mlog(ML_ERROR, "incompatible volume signature: %8s\n",
  704. hdr->signature);
  705. status = -EINVAL;
  706. }
  707. brelse(*bh);
  708. *bh = NULL;
  709. if (status < 0) {
  710. mlog(ML_ERROR, "This is an ocfs v1 filesystem which must be "
  711. "upgraded before mounting with ocfs v2\n");
  712. goto bail;
  713. }
  714. /*
  715. * Now check at magic offset for 512, 1024, 2048, 4096
  716. * blocksizes. 4096 is the maximum blocksize because it is
  717. * the minimum clustersize.
  718. */
  719. status = -EINVAL;
  720. for (blksize = *sector_size;
  721. blksize <= OCFS2_MAX_BLOCKSIZE;
  722. blksize <<= 1) {
  723. tmpstat = ocfs2_get_sector(sb, bh,
  724. OCFS2_SUPER_BLOCK_BLKNO,
  725. blksize);
  726. if (tmpstat < 0) {
  727. status = tmpstat;
  728. mlog_errno(status);
  729. break;
  730. }
  731. di = (struct ocfs2_dinode *) (*bh)->b_data;
  732. memset(stats, 0, sizeof(struct ocfs2_blockcheck_stats));
  733. spin_lock_init(&stats->b_lock);
  734. tmpstat = ocfs2_verify_volume(di, *bh, blksize, stats);
  735. if (tmpstat < 0) {
  736. brelse(*bh);
  737. *bh = NULL;
  738. }
  739. if (tmpstat != -EAGAIN) {
  740. status = tmpstat;
  741. break;
  742. }
  743. }
  744. bail:
  745. return status;
  746. }
  747. static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
  748. {
  749. u32 hb_enabled = OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL;
  750. if (osb->s_mount_opt & hb_enabled) {
  751. if (ocfs2_mount_local(osb)) {
  752. mlog(ML_ERROR, "Cannot heartbeat on a locally "
  753. "mounted device.\n");
  754. return -EINVAL;
  755. }
  756. if (ocfs2_userspace_stack(osb)) {
  757. mlog(ML_ERROR, "Userspace stack expected, but "
  758. "o2cb heartbeat arguments passed to mount\n");
  759. return -EINVAL;
  760. }
  761. if (((osb->s_mount_opt & OCFS2_MOUNT_HB_GLOBAL) &&
  762. !ocfs2_cluster_o2cb_global_heartbeat(osb)) ||
  763. ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) &&
  764. ocfs2_cluster_o2cb_global_heartbeat(osb))) {
  765. mlog(ML_ERROR, "Mismatching o2cb heartbeat modes\n");
  766. return -EINVAL;
  767. }
  768. }
  769. if (!(osb->s_mount_opt & hb_enabled)) {
  770. if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) &&
  771. !ocfs2_userspace_stack(osb)) {
  772. mlog(ML_ERROR, "Heartbeat has to be started to mount "
  773. "a read-write clustered device.\n");
  774. return -EINVAL;
  775. }
  776. }
  777. return 0;
  778. }
  779. /*
  780. * If we're using a userspace stack, mount should have passed
  781. * a name that matches the disk. If not, mount should not
  782. * have passed a stack.
  783. */
  784. static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb,
  785. struct mount_options *mopt)
  786. {
  787. if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) {
  788. mlog(ML_ERROR,
  789. "cluster stack passed to mount, but this filesystem "
  790. "does not support it\n");
  791. return -EINVAL;
  792. }
  793. if (ocfs2_userspace_stack(osb) &&
  794. strncmp(osb->osb_cluster_stack, mopt->cluster_stack,
  795. OCFS2_STACK_LABEL_LEN)) {
  796. mlog(ML_ERROR,
  797. "cluster stack passed to mount (\"%s\") does not "
  798. "match the filesystem (\"%s\")\n",
  799. mopt->cluster_stack,
  800. osb->osb_cluster_stack);
  801. return -EINVAL;
  802. }
  803. return 0;
  804. }
  805. static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend)
  806. {
  807. int type;
  808. struct super_block *sb = osb->sb;
  809. unsigned int feature[OCFS2_MAXQUOTAS] = {
  810. OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
  811. OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
  812. int status = 0;
  813. for (type = 0; type < OCFS2_MAXQUOTAS; type++) {
  814. if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
  815. continue;
  816. if (unsuspend)
  817. status = dquot_resume(sb, type);
  818. else {
  819. struct ocfs2_mem_dqinfo *oinfo;
  820. /* Cancel periodic syncing before suspending */
  821. oinfo = sb_dqinfo(sb, type)->dqi_priv;
  822. cancel_delayed_work_sync(&oinfo->dqi_sync_work);
  823. status = dquot_suspend(sb, type);
  824. }
  825. if (status < 0)
  826. break;
  827. }
  828. if (status < 0)
  829. mlog(ML_ERROR, "Failed to suspend/unsuspend quotas on "
  830. "remount (error = %d).\n", status);
  831. return status;
  832. }
  833. static int ocfs2_enable_quotas(struct ocfs2_super *osb)
  834. {
  835. struct inode *inode[OCFS2_MAXQUOTAS] = { NULL, NULL };
  836. struct super_block *sb = osb->sb;
  837. unsigned int feature[OCFS2_MAXQUOTAS] = {
  838. OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
  839. OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
  840. unsigned int ino[OCFS2_MAXQUOTAS] = {
  841. LOCAL_USER_QUOTA_SYSTEM_INODE,
  842. LOCAL_GROUP_QUOTA_SYSTEM_INODE };
  843. int status;
  844. int type;
  845. sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NEGATIVE_USAGE;
  846. for (type = 0; type < OCFS2_MAXQUOTAS; type++) {
  847. if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
  848. continue;
  849. inode[type] = ocfs2_get_system_file_inode(osb, ino[type],
  850. osb->slot_num);
  851. if (!inode[type]) {
  852. status = -ENOENT;
  853. goto out_quota_off;
  854. }
  855. status = dquot_enable(inode[type], type, QFMT_OCFS2,
  856. DQUOT_USAGE_ENABLED);
  857. if (status < 0)
  858. goto out_quota_off;
  859. }
  860. for (type = 0; type < OCFS2_MAXQUOTAS; type++)
  861. iput(inode[type]);
  862. return 0;
  863. out_quota_off:
  864. ocfs2_disable_quotas(osb);
  865. for (type = 0; type < OCFS2_MAXQUOTAS; type++)
  866. iput(inode[type]);
  867. mlog_errno(status);
  868. return status;
  869. }
  870. static void ocfs2_disable_quotas(struct ocfs2_super *osb)
  871. {
  872. int type;
  873. struct inode *inode;
  874. struct super_block *sb = osb->sb;
  875. struct ocfs2_mem_dqinfo *oinfo;
  876. /* We mostly ignore errors in this function because there's not much
  877. * we can do when we see them */
  878. for (type = 0; type < OCFS2_MAXQUOTAS; type++) {
  879. if (!sb_has_quota_loaded(sb, type))
  880. continue;
  881. oinfo = sb_dqinfo(sb, type)->dqi_priv;
  882. cancel_delayed_work_sync(&oinfo->dqi_sync_work);
  883. inode = igrab(sb->s_dquot.files[type]);
  884. /* Turn off quotas. This will remove all dquot structures from
  885. * memory and so they will be automatically synced to global
  886. * quota files */
  887. dquot_disable(sb, type, DQUOT_USAGE_ENABLED |
  888. DQUOT_LIMITS_ENABLED);
  889. if (!inode)
  890. continue;
  891. iput(inode);
  892. }
  893. }
  894. static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
  895. {
  896. struct dentry *root;
  897. int status, sector_size;
  898. struct mount_options parsed_options;
  899. struct inode *inode = NULL;
  900. struct ocfs2_super *osb = NULL;
  901. struct buffer_head *bh = NULL;
  902. char nodestr[12];
  903. struct ocfs2_blockcheck_stats stats;
  904. trace_ocfs2_fill_super(sb, data, silent);
  905. if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) {
  906. status = -EINVAL;
  907. goto read_super_error;
  908. }
  909. /* probe for superblock */
  910. status = ocfs2_sb_probe(sb, &bh, &sector_size, &stats);
  911. if (status < 0) {
  912. mlog(ML_ERROR, "superblock probe failed!\n");
  913. goto read_super_error;
  914. }
  915. status = ocfs2_initialize_super(sb, bh, sector_size, &stats);
  916. osb = OCFS2_SB(sb);
  917. if (status < 0) {
  918. mlog_errno(status);
  919. goto read_super_error;
  920. }
  921. brelse(bh);
  922. bh = NULL;
  923. if (!ocfs2_check_set_options(sb, &parsed_options)) {
  924. status = -EINVAL;
  925. goto read_super_error;
  926. }
  927. osb->s_mount_opt = parsed_options.mount_opt;
  928. osb->s_atime_quantum = parsed_options.atime_quantum;
  929. osb->preferred_slot = parsed_options.slot;
  930. osb->osb_commit_interval = parsed_options.commit_interval;
  931. ocfs2_la_set_sizes(osb, parsed_options.localalloc_opt);
  932. osb->osb_resv_level = parsed_options.resv_level;
  933. osb->osb_dir_resv_level = parsed_options.resv_level;
  934. if (parsed_options.dir_resv_level == -1)
  935. osb->osb_dir_resv_level = parsed_options.resv_level;
  936. else
  937. osb->osb_dir_resv_level = parsed_options.dir_resv_level;
  938. status = ocfs2_verify_userspace_stack(osb, &parsed_options);
  939. if (status)
  940. goto read_super_error;
  941. sb->s_magic = OCFS2_SUPER_MAGIC;
  942. sb->s_flags = (sb->s_flags & ~(MS_POSIXACL | MS_NOSEC)) |
  943. ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
  944. /* Hard readonly mode only if: bdev_read_only, MS_RDONLY,
  945. * heartbeat=none */
  946. if (bdev_read_only(sb->s_bdev)) {
  947. if (!(sb->s_flags & MS_RDONLY)) {
  948. status = -EACCES;
  949. mlog(ML_ERROR, "Readonly device detected but readonly "
  950. "mount was not specified.\n");
  951. goto read_super_error;
  952. }
  953. /* You should not be able to start a local heartbeat
  954. * on a readonly device. */
  955. if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
  956. status = -EROFS;
  957. mlog(ML_ERROR, "Local heartbeat specified on readonly "
  958. "device.\n");
  959. goto read_super_error;
  960. }
  961. status = ocfs2_check_journals_nolocks(osb);
  962. if (status < 0) {
  963. if (status == -EROFS)
  964. mlog(ML_ERROR, "Recovery required on readonly "
  965. "file system, but write access is "
  966. "unavailable.\n");
  967. else
  968. mlog_errno(status);
  969. goto read_super_error;
  970. }
  971. ocfs2_set_ro_flag(osb, 1);
  972. printk(KERN_NOTICE "ocfs2: Readonly device (%s) detected. "
  973. "Cluster services will not be used for this mount. "
  974. "Recovery will be skipped.\n", osb->dev_str);
  975. }
  976. if (!ocfs2_is_hard_readonly(osb)) {
  977. if (sb->s_flags & MS_RDONLY)
  978. ocfs2_set_ro_flag(osb, 0);
  979. }
  980. status = ocfs2_verify_heartbeat(osb);
  981. if (status < 0) {
  982. mlog_errno(status);
  983. goto read_super_error;
  984. }
  985. osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
  986. ocfs2_debugfs_root);
  987. if (!osb->osb_debug_root) {
  988. status = -EINVAL;
  989. mlog(ML_ERROR, "Unable to create per-mount debugfs root.\n");
  990. goto read_super_error;
  991. }
  992. osb->osb_ctxt = debugfs_create_file("fs_state", S_IFREG|S_IRUSR,
  993. osb->osb_debug_root,
  994. osb,
  995. &ocfs2_osb_debug_fops);
  996. if (!osb->osb_ctxt) {
  997. status = -EINVAL;
  998. mlog_errno(status);
  999. goto read_super_error;
  1000. }
  1001. if (ocfs2_meta_ecc(osb)) {
  1002. status = ocfs2_blockcheck_stats_debugfs_install(
  1003. &osb->osb_ecc_stats,
  1004. osb->osb_debug_root);
  1005. if (status) {
  1006. mlog(ML_ERROR,
  1007. "Unable to create blockcheck statistics "
  1008. "files\n");
  1009. goto read_super_error;
  1010. }
  1011. }
  1012. status = ocfs2_mount_volume(sb);
  1013. if (status < 0)
  1014. goto read_super_error;
  1015. if (osb->root_inode)
  1016. inode = igrab(osb->root_inode);
  1017. if (!inode) {
  1018. status = -EIO;
  1019. mlog_errno(status);
  1020. goto read_super_error;
  1021. }
  1022. root = d_make_root(inode);
  1023. if (!root) {
  1024. status = -ENOMEM;
  1025. mlog_errno(status);
  1026. goto read_super_error;
  1027. }
  1028. sb->s_root = root;
  1029. ocfs2_complete_mount_recovery(osb);
  1030. if (ocfs2_mount_local(osb))
  1031. snprintf(nodestr, sizeof(nodestr), "local");
  1032. else
  1033. snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
  1034. printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
  1035. "with %s data mode.\n",
  1036. osb->dev_str, nodestr, osb->slot_num,
  1037. osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
  1038. "ordered");
  1039. atomic_set(&osb->vol_state, VOLUME_MOUNTED);
  1040. wake_up(&osb->osb_mount_event);
  1041. /* Now we can initialize quotas because we can afford to wait
  1042. * for cluster locks recovery now. That also means that truncation
  1043. * log recovery can happen but that waits for proper quota setup */
  1044. if (!(sb->s_flags & MS_RDONLY)) {
  1045. status = ocfs2_enable_quotas(osb);
  1046. if (status < 0) {
  1047. /* We have to err-out specially here because
  1048. * s_root is already set */
  1049. mlog_errno(status);
  1050. atomic_set(&osb->vol_state, VOLUME_DISABLED);
  1051. wake_up(&osb->osb_mount_event);
  1052. return status;
  1053. }
  1054. }
  1055. ocfs2_complete_quota_recovery(osb);
  1056. /* Now we wake up again for processes waiting for quotas */
  1057. atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS);
  1058. wake_up(&osb->osb_mount_event);
  1059. /* Start this when the mount is almost sure of being successful */
  1060. ocfs2_orphan_scan_start(osb);
  1061. /* Create filecheck sysfile /sys/fs/ocfs2/<devname>/filecheck */
  1062. ocfs2_filecheck_create_sysfs(sb);
  1063. return status;
  1064. read_super_error:
  1065. brelse(bh);
  1066. if (osb) {
  1067. atomic_set(&osb->vol_state, VOLUME_DISABLED);
  1068. wake_up(&osb->osb_mount_event);
  1069. ocfs2_dismount_volume(sb, 1);
  1070. }
  1071. if (status)
  1072. mlog_errno(status);
  1073. return status;
  1074. }
  1075. static struct dentry *ocfs2_mount(struct file_system_type *fs_type,
  1076. int flags,
  1077. const char *dev_name,
  1078. void *data)
  1079. {
  1080. return mount_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super);
  1081. }
  1082. static struct file_system_type ocfs2_fs_type = {
  1083. .owner = THIS_MODULE,
  1084. .name = "ocfs2",
  1085. .mount = ocfs2_mount,
  1086. .kill_sb = kill_block_super,
  1087. .fs_flags = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE,
  1088. .next = NULL
  1089. };
  1090. MODULE_ALIAS_FS("ocfs2");
  1091. static int ocfs2_check_set_options(struct super_block *sb,
  1092. struct mount_options *options)
  1093. {
  1094. if (options->mount_opt & OCFS2_MOUNT_USRQUOTA &&
  1095. !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
  1096. OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
  1097. mlog(ML_ERROR, "User quotas were requested, but this "
  1098. "filesystem does not have the feature enabled.\n");
  1099. return 0;
  1100. }
  1101. if (options->mount_opt & OCFS2_MOUNT_GRPQUOTA &&
  1102. !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
  1103. OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
  1104. mlog(ML_ERROR, "Group quotas were requested, but this "
  1105. "filesystem does not have the feature enabled.\n");
  1106. return 0;
  1107. }
  1108. if (options->mount_opt & OCFS2_MOUNT_POSIX_ACL &&
  1109. !OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR)) {
  1110. mlog(ML_ERROR, "ACL support requested but extended attributes "
  1111. "feature is not enabled\n");
  1112. return 0;
  1113. }
  1114. /* No ACL setting specified? Use XATTR feature... */
  1115. if (!(options->mount_opt & (OCFS2_MOUNT_POSIX_ACL |
  1116. OCFS2_MOUNT_NO_POSIX_ACL))) {
  1117. if (OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR))
  1118. options->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
  1119. else
  1120. options->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
  1121. }
  1122. return 1;
  1123. }
  1124. static int ocfs2_parse_options(struct super_block *sb,
  1125. char *options,
  1126. struct mount_options *mopt,
  1127. int is_remount)
  1128. {
  1129. int status, user_stack = 0;
  1130. char *p;
  1131. u32 tmp;
  1132. int token, option;
  1133. substring_t args[MAX_OPT_ARGS];
  1134. trace_ocfs2_parse_options(is_remount, options ? options : "(none)");
  1135. mopt->commit_interval = 0;
  1136. mopt->mount_opt = OCFS2_MOUNT_NOINTR;
  1137. mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
  1138. mopt->slot = OCFS2_INVALID_SLOT;
  1139. mopt->localalloc_opt = -1;
  1140. mopt->cluster_stack[0] = '\0';
  1141. mopt->resv_level = OCFS2_DEFAULT_RESV_LEVEL;
  1142. mopt->dir_resv_level = -1;
  1143. if (!options) {
  1144. status = 1;
  1145. goto bail;
  1146. }
  1147. while ((p = strsep(&options, ",")) != NULL) {
  1148. if (!*p)
  1149. continue;
  1150. token = match_token(p, tokens, args);
  1151. switch (token) {
  1152. case Opt_hb_local:
  1153. mopt->mount_opt |= OCFS2_MOUNT_HB_LOCAL;
  1154. break;
  1155. case Opt_hb_none:
  1156. mopt->mount_opt |= OCFS2_MOUNT_HB_NONE;
  1157. break;
  1158. case Opt_hb_global:
  1159. mopt->mount_opt |= OCFS2_MOUNT_HB_GLOBAL;
  1160. break;
  1161. case Opt_barrier:
  1162. if (match_int(&args[0], &option)) {
  1163. status = 0;
  1164. goto bail;
  1165. }
  1166. if (option)
  1167. mopt->mount_opt |= OCFS2_MOUNT_BARRIER;
  1168. else
  1169. mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER;
  1170. break;
  1171. case Opt_intr:
  1172. mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR;
  1173. break;
  1174. case Opt_nointr:
  1175. mopt->mount_opt |= OCFS2_MOUNT_NOINTR;
  1176. break;
  1177. case Opt_err_panic:
  1178. mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_CONT;
  1179. mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_ROFS;
  1180. mopt->mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
  1181. break;
  1182. case Opt_err_ro:
  1183. mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_CONT;
  1184. mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
  1185. mopt->mount_opt |= OCFS2_MOUNT_ERRORS_ROFS;
  1186. break;
  1187. case Opt_err_cont:
  1188. mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_ROFS;
  1189. mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
  1190. mopt->mount_opt |= OCFS2_MOUNT_ERRORS_CONT;
  1191. break;
  1192. case Opt_data_ordered:
  1193. mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK;
  1194. break;
  1195. case Opt_data_writeback:
  1196. mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
  1197. break;
  1198. case Opt_user_xattr:
  1199. mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
  1200. break;
  1201. case Opt_nouser_xattr:
  1202. mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
  1203. break;
  1204. case Opt_atime_quantum:
  1205. if (match_int(&args[0], &option)) {
  1206. status = 0;
  1207. goto bail;
  1208. }
  1209. if (option >= 0)
  1210. mopt->atime_quantum = option;
  1211. break;
  1212. case Opt_slot:
  1213. if (match_int(&args[0], &option)) {
  1214. status = 0;
  1215. goto bail;
  1216. }
  1217. if (option)
  1218. mopt->slot = (s16)option;
  1219. break;
  1220. case Opt_commit:
  1221. if (match_int(&args[0], &option)) {
  1222. status = 0;
  1223. goto bail;
  1224. }
  1225. if (option < 0)
  1226. return 0;
  1227. if (option == 0)
  1228. option = JBD2_DEFAULT_MAX_COMMIT_AGE;
  1229. mopt->commit_interval = HZ * option;
  1230. break;
  1231. case Opt_localalloc:
  1232. if (match_int(&args[0], &option)) {
  1233. status = 0;
  1234. goto bail;
  1235. }
  1236. if (option >= 0)
  1237. mopt->localalloc_opt = option;
  1238. break;
  1239. case Opt_localflocks:
  1240. /*
  1241. * Changing this during remount could race
  1242. * flock() requests, or "unbalance" existing
  1243. * ones (e.g., a lock is taken in one mode but
  1244. * dropped in the other). If users care enough
  1245. * to flip locking modes during remount, we
  1246. * could add a "local" flag to individual
  1247. * flock structures for proper tracking of
  1248. * state.
  1249. */
  1250. if (!is_remount)
  1251. mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
  1252. break;
  1253. case Opt_stack:
  1254. /* Check both that the option we were passed
  1255. * is of the right length and that it is a proper
  1256. * string of the right length.
  1257. */
  1258. if (((args[0].to - args[0].from) !=
  1259. OCFS2_STACK_LABEL_LEN) ||
  1260. (strnlen(args[0].from,
  1261. OCFS2_STACK_LABEL_LEN) !=
  1262. OCFS2_STACK_LABEL_LEN)) {
  1263. mlog(ML_ERROR,
  1264. "Invalid cluster_stack option\n");
  1265. status = 0;
  1266. goto bail;
  1267. }
  1268. memcpy(mopt->cluster_stack, args[0].from,
  1269. OCFS2_STACK_LABEL_LEN);
  1270. mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
  1271. /*
  1272. * Open code the memcmp here as we don't have
  1273. * an osb to pass to
  1274. * ocfs2_userspace_stack().
  1275. */
  1276. if (memcmp(mopt->cluster_stack,
  1277. OCFS2_CLASSIC_CLUSTER_STACK,
  1278. OCFS2_STACK_LABEL_LEN))
  1279. user_stack = 1;
  1280. break;
  1281. case Opt_inode64:
  1282. mopt->mount_opt |= OCFS2_MOUNT_INODE64;
  1283. break;
  1284. case Opt_usrquota:
  1285. mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA;
  1286. break;
  1287. case Opt_grpquota:
  1288. mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA;
  1289. break;
  1290. case Opt_coherency_buffered:
  1291. mopt->mount_opt |= OCFS2_MOUNT_COHERENCY_BUFFERED;
  1292. break;
  1293. case Opt_coherency_full:
  1294. mopt->mount_opt &= ~OCFS2_MOUNT_COHERENCY_BUFFERED;
  1295. break;
  1296. case Opt_acl:
  1297. mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
  1298. mopt->mount_opt &= ~OCFS2_MOUNT_NO_POSIX_ACL;
  1299. break;
  1300. case Opt_noacl:
  1301. mopt->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
  1302. mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
  1303. break;
  1304. case Opt_resv_level:
  1305. if (is_remount)
  1306. break;
  1307. if (match_int(&args[0], &option)) {
  1308. status = 0;
  1309. goto bail;
  1310. }
  1311. if (option >= OCFS2_MIN_RESV_LEVEL &&
  1312. option < OCFS2_MAX_RESV_LEVEL)
  1313. mopt->resv_level = option;
  1314. break;
  1315. case Opt_dir_resv_level:
  1316. if (is_remount)
  1317. break;
  1318. if (match_int(&args[0], &option)) {
  1319. status = 0;
  1320. goto bail;
  1321. }
  1322. if (option >= OCFS2_MIN_RESV_LEVEL &&
  1323. option < OCFS2_MAX_RESV_LEVEL)
  1324. mopt->dir_resv_level = option;
  1325. break;
  1326. case Opt_journal_async_commit:
  1327. mopt->mount_opt |= OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT;
  1328. break;
  1329. default:
  1330. mlog(ML_ERROR,
  1331. "Unrecognized mount option \"%s\" "
  1332. "or missing value\n", p);
  1333. status = 0;
  1334. goto bail;
  1335. }
  1336. }
  1337. if (user_stack == 0) {
  1338. /* Ensure only one heartbeat mode */
  1339. tmp = mopt->mount_opt & (OCFS2_MOUNT_HB_LOCAL |
  1340. OCFS2_MOUNT_HB_GLOBAL |
  1341. OCFS2_MOUNT_HB_NONE);
  1342. if (hweight32(tmp) != 1) {
  1343. mlog(ML_ERROR, "Invalid heartbeat mount options\n");
  1344. status = 0;
  1345. goto bail;
  1346. }
  1347. }
  1348. status = 1;
  1349. bail:
  1350. return status;
  1351. }
  1352. static int ocfs2_show_options(struct seq_file *s, struct dentry *root)
  1353. {
  1354. struct ocfs2_super *osb = OCFS2_SB(root->d_sb);
  1355. unsigned long opts = osb->s_mount_opt;
  1356. unsigned int local_alloc_megs;
  1357. if (opts & (OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL)) {
  1358. seq_printf(s, ",_netdev");
  1359. if (opts & OCFS2_MOUNT_HB_LOCAL)
  1360. seq_printf(s, ",%s", OCFS2_HB_LOCAL);
  1361. else
  1362. seq_printf(s, ",%s", OCFS2_HB_GLOBAL);
  1363. } else
  1364. seq_printf(s, ",%s", OCFS2_HB_NONE);
  1365. if (opts & OCFS2_MOUNT_NOINTR)
  1366. seq_printf(s, ",nointr");
  1367. if (opts & OCFS2_MOUNT_DATA_WRITEBACK)
  1368. seq_printf(s, ",data=writeback");
  1369. else
  1370. seq_printf(s, ",data=ordered");
  1371. if (opts & OCFS2_MOUNT_BARRIER)
  1372. seq_printf(s, ",barrier=1");
  1373. if (opts & OCFS2_MOUNT_ERRORS_PANIC)
  1374. seq_printf(s, ",errors=panic");
  1375. else if (opts & OCFS2_MOUNT_ERRORS_CONT)
  1376. seq_printf(s, ",errors=continue");
  1377. else
  1378. seq_printf(s, ",errors=remount-ro");
  1379. if (osb->preferred_slot != OCFS2_INVALID_SLOT)
  1380. seq_printf(s, ",preferred_slot=%d", osb->preferred_slot);
  1381. seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum);
  1382. if (osb->osb_commit_interval)
  1383. seq_printf(s, ",commit=%u",
  1384. (unsigned) (osb->osb_commit_interval / HZ));
  1385. local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits);
  1386. if (local_alloc_megs != ocfs2_la_default_mb(osb))
  1387. seq_printf(s, ",localalloc=%d", local_alloc_megs);
  1388. if (opts & OCFS2_MOUNT_LOCALFLOCKS)
  1389. seq_printf(s, ",localflocks,");
  1390. if (osb->osb_cluster_stack[0])
  1391. seq_show_option_n(s, "cluster_stack", osb->osb_cluster_stack,
  1392. OCFS2_STACK_LABEL_LEN);
  1393. if (opts & OCFS2_MOUNT_USRQUOTA)
  1394. seq_printf(s, ",usrquota");
  1395. if (opts & OCFS2_MOUNT_GRPQUOTA)
  1396. seq_printf(s, ",grpquota");
  1397. if (opts & OCFS2_MOUNT_COHERENCY_BUFFERED)
  1398. seq_printf(s, ",coherency=buffered");
  1399. else
  1400. seq_printf(s, ",coherency=full");
  1401. if (opts & OCFS2_MOUNT_NOUSERXATTR)
  1402. seq_printf(s, ",nouser_xattr");
  1403. else
  1404. seq_printf(s, ",user_xattr");
  1405. if (opts & OCFS2_MOUNT_INODE64)
  1406. seq_printf(s, ",inode64");
  1407. if (opts & OCFS2_MOUNT_POSIX_ACL)
  1408. seq_printf(s, ",acl");
  1409. else
  1410. seq_printf(s, ",noacl");
  1411. if (osb->osb_resv_level != OCFS2_DEFAULT_RESV_LEVEL)
  1412. seq_printf(s, ",resv_level=%d", osb->osb_resv_level);
  1413. if (osb->osb_dir_resv_level != osb->osb_resv_level)
  1414. seq_printf(s, ",dir_resv_level=%d", osb->osb_resv_level);
  1415. if (opts & OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT)
  1416. seq_printf(s, ",journal_async_commit");
  1417. return 0;
  1418. }
  1419. static int __init ocfs2_init(void)
  1420. {
  1421. int status;
  1422. status = init_ocfs2_uptodate_cache();
  1423. if (status < 0)
  1424. goto out1;
  1425. status = ocfs2_initialize_mem_caches();
  1426. if (status < 0)
  1427. goto out2;
  1428. ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
  1429. if (!ocfs2_debugfs_root) {
  1430. status = -ENOMEM;
  1431. mlog(ML_ERROR, "Unable to create ocfs2 debugfs root.\n");
  1432. goto out3;
  1433. }
  1434. ocfs2_set_locking_protocol();
  1435. status = register_quota_format(&ocfs2_quota_format);
  1436. if (status < 0)
  1437. goto out3;
  1438. status = register_filesystem(&ocfs2_fs_type);
  1439. if (!status)
  1440. return 0;
  1441. unregister_quota_format(&ocfs2_quota_format);
  1442. out3:
  1443. debugfs_remove(ocfs2_debugfs_root);
  1444. ocfs2_free_mem_caches();
  1445. out2:
  1446. exit_ocfs2_uptodate_cache();
  1447. out1:
  1448. mlog_errno(status);
  1449. return status;
  1450. }
  1451. static void __exit ocfs2_exit(void)
  1452. {
  1453. unregister_quota_format(&ocfs2_quota_format);
  1454. debugfs_remove(ocfs2_debugfs_root);
  1455. ocfs2_free_mem_caches();
  1456. unregister_filesystem(&ocfs2_fs_type);
  1457. exit_ocfs2_uptodate_cache();
  1458. }
  1459. static void ocfs2_put_super(struct super_block *sb)
  1460. {
  1461. trace_ocfs2_put_super(sb);
  1462. ocfs2_sync_blockdev(sb);
  1463. ocfs2_dismount_volume(sb, 0);
  1464. ocfs2_filecheck_remove_sysfs(sb);
  1465. }
  1466. static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
  1467. {
  1468. struct ocfs2_super *osb;
  1469. u32 numbits, freebits;
  1470. int status;
  1471. struct ocfs2_dinode *bm_lock;
  1472. struct buffer_head *bh = NULL;
  1473. struct inode *inode = NULL;
  1474. trace_ocfs2_statfs(dentry->d_sb, buf);
  1475. osb = OCFS2_SB(dentry->d_sb);
  1476. inode = ocfs2_get_system_file_inode(osb,
  1477. GLOBAL_BITMAP_SYSTEM_INODE,
  1478. OCFS2_INVALID_SLOT);
  1479. if (!inode) {
  1480. mlog(ML_ERROR, "failed to get bitmap inode\n");
  1481. status = -EIO;
  1482. goto bail;
  1483. }
  1484. status = ocfs2_inode_lock(inode, &bh, 0);
  1485. if (status < 0) {
  1486. mlog_errno(status);
  1487. goto bail;
  1488. }
  1489. bm_lock = (struct ocfs2_dinode *) bh->b_data;
  1490. numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total);
  1491. freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used);
  1492. buf->f_type = OCFS2_SUPER_MAGIC;
  1493. buf->f_bsize = dentry->d_sb->s_blocksize;
  1494. buf->f_namelen = OCFS2_MAX_FILENAME_LEN;
  1495. buf->f_blocks = ((sector_t) numbits) *
  1496. (osb->s_clustersize >> osb->sb->s_blocksize_bits);
  1497. buf->f_bfree = ((sector_t) freebits) *
  1498. (osb->s_clustersize >> osb->sb->s_blocksize_bits);
  1499. buf->f_bavail = buf->f_bfree;
  1500. buf->f_files = numbits;
  1501. buf->f_ffree = freebits;
  1502. buf->f_fsid.val[0] = crc32_le(0, osb->uuid_str, OCFS2_VOL_UUID_LEN)
  1503. & 0xFFFFFFFFUL;
  1504. buf->f_fsid.val[1] = crc32_le(0, osb->uuid_str + OCFS2_VOL_UUID_LEN,
  1505. OCFS2_VOL_UUID_LEN) & 0xFFFFFFFFUL;
  1506. brelse(bh);
  1507. ocfs2_inode_unlock(inode, 0);
  1508. status = 0;
  1509. bail:
  1510. iput(inode);
  1511. if (status)
  1512. mlog_errno(status);
  1513. return status;
  1514. }
  1515. static void ocfs2_inode_init_once(void *data)
  1516. {
  1517. struct ocfs2_inode_info *oi = data;
  1518. oi->ip_flags = 0;
  1519. oi->ip_open_count = 0;
  1520. spin_lock_init(&oi->ip_lock);
  1521. ocfs2_extent_map_init(&oi->vfs_inode);
  1522. INIT_LIST_HEAD(&oi->ip_io_markers);
  1523. INIT_LIST_HEAD(&oi->ip_unwritten_list);
  1524. oi->ip_dir_start_lookup = 0;
  1525. init_rwsem(&oi->ip_alloc_sem);
  1526. init_rwsem(&oi->ip_xattr_sem);
  1527. mutex_init(&oi->ip_io_mutex);
  1528. oi->ip_blkno = 0ULL;
  1529. oi->ip_clusters = 0;
  1530. ocfs2_resv_init_once(&oi->ip_la_data_resv);
  1531. ocfs2_lock_res_init_once(&oi->ip_rw_lockres);
  1532. ocfs2_lock_res_init_once(&oi->ip_inode_lockres);
  1533. ocfs2_lock_res_init_once(&oi->ip_open_lockres);
  1534. ocfs2_metadata_cache_init(INODE_CACHE(&oi->vfs_inode),
  1535. &ocfs2_inode_caching_ops);
  1536. inode_init_once(&oi->vfs_inode);
  1537. }
  1538. static int ocfs2_initialize_mem_caches(void)
  1539. {
  1540. ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache",
  1541. sizeof(struct ocfs2_inode_info),
  1542. 0,
  1543. (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
  1544. SLAB_MEM_SPREAD|SLAB_ACCOUNT),
  1545. ocfs2_inode_init_once);
  1546. ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache",
  1547. sizeof(struct ocfs2_dquot),
  1548. 0,
  1549. (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
  1550. SLAB_MEM_SPREAD),
  1551. NULL);
  1552. ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache",
  1553. sizeof(struct ocfs2_quota_chunk),
  1554. 0,
  1555. (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
  1556. NULL);
  1557. if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
  1558. !ocfs2_qf_chunk_cachep) {
  1559. if (ocfs2_inode_cachep)
  1560. kmem_cache_destroy(ocfs2_inode_cachep);
  1561. if (ocfs2_dquot_cachep)
  1562. kmem_cache_destroy(ocfs2_dquot_cachep);
  1563. if (ocfs2_qf_chunk_cachep)
  1564. kmem_cache_destroy(ocfs2_qf_chunk_cachep);
  1565. return -ENOMEM;
  1566. }
  1567. return 0;
  1568. }
  1569. static void ocfs2_free_mem_caches(void)
  1570. {
  1571. /*
  1572. * Make sure all delayed rcu free inodes are flushed before we
  1573. * destroy cache.
  1574. */
  1575. rcu_barrier();
  1576. if (ocfs2_inode_cachep)
  1577. kmem_cache_destroy(ocfs2_inode_cachep);
  1578. ocfs2_inode_cachep = NULL;
  1579. if (ocfs2_dquot_cachep)
  1580. kmem_cache_destroy(ocfs2_dquot_cachep);
  1581. ocfs2_dquot_cachep = NULL;
  1582. if (ocfs2_qf_chunk_cachep)
  1583. kmem_cache_destroy(ocfs2_qf_chunk_cachep);
  1584. ocfs2_qf_chunk_cachep = NULL;
  1585. }
  1586. static int ocfs2_get_sector(struct super_block *sb,
  1587. struct buffer_head **bh,
  1588. int block,
  1589. int sect_size)
  1590. {
  1591. if (!sb_set_blocksize(sb, sect_size)) {
  1592. mlog(ML_ERROR, "unable to set blocksize\n");
  1593. return -EIO;
  1594. }
  1595. *bh = sb_getblk(sb, block);
  1596. if (!*bh) {
  1597. mlog_errno(-ENOMEM);
  1598. return -ENOMEM;
  1599. }
  1600. lock_buffer(*bh);
  1601. if (!buffer_dirty(*bh))
  1602. clear_buffer_uptodate(*bh);
  1603. unlock_buffer(*bh);
  1604. ll_rw_block(REQ_OP_READ, 0, 1, bh);
  1605. wait_on_buffer(*bh);
  1606. if (!buffer_uptodate(*bh)) {
  1607. mlog_errno(-EIO);
  1608. brelse(*bh);
  1609. *bh = NULL;
  1610. return -EIO;
  1611. }
  1612. return 0;
  1613. }
  1614. static int ocfs2_mount_volume(struct super_block *sb)
  1615. {
  1616. int status = 0;
  1617. int unlock_super = 0;
  1618. struct ocfs2_super *osb = OCFS2_SB(sb);
  1619. if (ocfs2_is_hard_readonly(osb))
  1620. goto leave;
  1621. status = ocfs2_dlm_init(osb);
  1622. if (status < 0) {
  1623. mlog_errno(status);
  1624. goto leave;
  1625. }
  1626. status = ocfs2_super_lock(osb, 1);
  1627. if (status < 0) {
  1628. mlog_errno(status);
  1629. goto leave;
  1630. }
  1631. unlock_super = 1;
  1632. /* This will load up the node map and add ourselves to it. */
  1633. status = ocfs2_find_slot(osb);
  1634. if (status < 0) {
  1635. mlog_errno(status);
  1636. goto leave;
  1637. }
  1638. /* load all node-local system inodes */
  1639. status = ocfs2_init_local_system_inodes(osb);
  1640. if (status < 0) {
  1641. mlog_errno(status);
  1642. goto leave;
  1643. }
  1644. status = ocfs2_check_volume(osb);
  1645. if (status < 0) {
  1646. mlog_errno(status);
  1647. goto leave;
  1648. }
  1649. status = ocfs2_truncate_log_init(osb);
  1650. if (status < 0)
  1651. mlog_errno(status);
  1652. leave:
  1653. if (unlock_super)
  1654. ocfs2_super_unlock(osb, 1);
  1655. return status;
  1656. }
  1657. static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
  1658. {
  1659. int tmp, hangup_needed = 0;
  1660. struct ocfs2_super *osb = NULL;
  1661. char nodestr[12];
  1662. trace_ocfs2_dismount_volume(sb);
  1663. BUG_ON(!sb);
  1664. osb = OCFS2_SB(sb);
  1665. BUG_ON(!osb);
  1666. debugfs_remove(osb->osb_ctxt);
  1667. /* Orphan scan should be stopped as early as possible */
  1668. ocfs2_orphan_scan_stop(osb);
  1669. ocfs2_disable_quotas(osb);
  1670. /* All dquots should be freed by now */
  1671. WARN_ON(!llist_empty(&osb->dquot_drop_list));
  1672. /* Wait for worker to be done with the work structure in osb */
  1673. cancel_work_sync(&osb->dquot_drop_work);
  1674. ocfs2_shutdown_local_alloc(osb);
  1675. ocfs2_truncate_log_shutdown(osb);
  1676. /* This will disable recovery and flush any recovery work. */
  1677. ocfs2_recovery_exit(osb);
  1678. ocfs2_journal_shutdown(osb);
  1679. ocfs2_sync_blockdev(sb);
  1680. ocfs2_purge_refcount_trees(osb);
  1681. /* No cluster connection means we've failed during mount, so skip
  1682. * all the steps which depended on that to complete. */
  1683. if (osb->cconn) {
  1684. tmp = ocfs2_super_lock(osb, 1);
  1685. if (tmp < 0) {
  1686. mlog_errno(tmp);
  1687. return;
  1688. }
  1689. }
  1690. if (osb->slot_num != OCFS2_INVALID_SLOT)
  1691. ocfs2_put_slot(osb);
  1692. if (osb->cconn)
  1693. ocfs2_super_unlock(osb, 1);
  1694. ocfs2_release_system_inodes(osb);
  1695. /*
  1696. * If we're dismounting due to mount error, mount.ocfs2 will clean
  1697. * up heartbeat. If we're a local mount, there is no heartbeat.
  1698. * If we failed before we got a uuid_str yet, we can't stop
  1699. * heartbeat. Otherwise, do it.
  1700. */
  1701. if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str &&
  1702. !ocfs2_is_hard_readonly(osb))
  1703. hangup_needed = 1;
  1704. if (osb->cconn)
  1705. ocfs2_dlm_shutdown(osb, hangup_needed);
  1706. ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats);
  1707. debugfs_remove(osb->osb_debug_root);
  1708. if (hangup_needed)
  1709. ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));
  1710. atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
  1711. if (ocfs2_mount_local(osb))
  1712. snprintf(nodestr, sizeof(nodestr), "local");
  1713. else
  1714. snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
  1715. printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
  1716. osb->dev_str, nodestr);
  1717. ocfs2_delete_osb(osb);
  1718. kfree(osb);
  1719. sb->s_dev = 0;
  1720. sb->s_fs_info = NULL;
  1721. }
  1722. static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid,
  1723. unsigned uuid_bytes)
  1724. {
  1725. int i, ret;
  1726. char *ptr;
  1727. BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN);
  1728. osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL);
  1729. if (osb->uuid_str == NULL)
  1730. return -ENOMEM;
  1731. for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) {
  1732. /* print with null */
  1733. ret = snprintf(ptr, 3, "%02X", uuid[i]);
  1734. if (ret != 2) /* drop super cleans up */
  1735. return -EINVAL;
  1736. /* then only advance past the last char */
  1737. ptr += 2;
  1738. }
  1739. return 0;
  1740. }
  1741. /* Make sure entire volume is addressable by our journal. Requires
  1742. osb_clusters_at_boot to be valid and for the journal to have been
  1743. initialized by ocfs2_journal_init(). */
  1744. static int ocfs2_journal_addressable(struct ocfs2_super *osb)
  1745. {
  1746. int status = 0;
  1747. u64 max_block =
  1748. ocfs2_clusters_to_blocks(osb->sb,
  1749. osb->osb_clusters_at_boot) - 1;
  1750. /* 32-bit block number is always OK. */
  1751. if (max_block <= (u32)~0ULL)
  1752. goto out;
  1753. /* Volume is "huge", so see if our journal is new enough to
  1754. support it. */
  1755. if (!(OCFS2_HAS_COMPAT_FEATURE(osb->sb,
  1756. OCFS2_FEATURE_COMPAT_JBD2_SB) &&
  1757. jbd2_journal_check_used_features(osb->journal->j_journal, 0, 0,
  1758. JBD2_FEATURE_INCOMPAT_64BIT))) {
  1759. mlog(ML_ERROR, "The journal cannot address the entire volume. "
  1760. "Enable the 'block64' journal option with tunefs.ocfs2");
  1761. status = -EFBIG;
  1762. goto out;
  1763. }
  1764. out:
  1765. return status;
  1766. }
  1767. static int ocfs2_initialize_super(struct super_block *sb,
  1768. struct buffer_head *bh,
  1769. int sector_size,
  1770. struct ocfs2_blockcheck_stats *stats)
  1771. {
  1772. int status;
  1773. int i, cbits, bbits;
  1774. struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
  1775. struct inode *inode = NULL;
  1776. struct ocfs2_journal *journal;
  1777. struct ocfs2_super *osb;
  1778. u64 total_blocks;
  1779. osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL);
  1780. if (!osb) {
  1781. status = -ENOMEM;
  1782. mlog_errno(status);
  1783. goto bail;
  1784. }
  1785. sb->s_fs_info = osb;
  1786. sb->s_op = &ocfs2_sops;
  1787. sb->s_d_op = &ocfs2_dentry_ops;
  1788. sb->s_export_op = &ocfs2_export_ops;
  1789. sb->s_qcop = &dquot_quotactl_sysfile_ops;
  1790. sb->dq_op = &ocfs2_quota_operations;
  1791. sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP;
  1792. sb->s_xattr = ocfs2_xattr_handlers;
  1793. sb->s_time_gran = 1;
  1794. sb->s_flags |= MS_NOATIME;
  1795. /* this is needed to support O_LARGEFILE */
  1796. cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
  1797. bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
  1798. sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
  1799. memcpy(sb->s_uuid, di->id2.i_super.s_uuid,
  1800. sizeof(di->id2.i_super.s_uuid));
  1801. osb->osb_dx_mask = (1 << (cbits - bbits)) - 1;
  1802. for (i = 0; i < 3; i++)
  1803. osb->osb_dx_seed[i] = le32_to_cpu(di->id2.i_super.s_dx_seed[i]);
  1804. osb->osb_dx_seed[3] = le32_to_cpu(di->id2.i_super.s_uuid_hash);
  1805. osb->sb = sb;
  1806. osb->s_sectsize_bits = blksize_bits(sector_size);
  1807. BUG_ON(!osb->s_sectsize_bits);
  1808. spin_lock_init(&osb->dc_task_lock);
  1809. init_waitqueue_head(&osb->dc_event);
  1810. osb->dc_work_sequence = 0;
  1811. osb->dc_wake_sequence = 0;
  1812. INIT_LIST_HEAD(&osb->blocked_lock_list);
  1813. osb->blocked_lock_count = 0;
  1814. spin_lock_init(&osb->osb_lock);
  1815. spin_lock_init(&osb->osb_xattr_lock);
  1816. ocfs2_init_steal_slots(osb);
  1817. mutex_init(&osb->system_file_mutex);
  1818. atomic_set(&osb->alloc_stats.moves, 0);
  1819. atomic_set(&osb->alloc_stats.local_data, 0);
  1820. atomic_set(&osb->alloc_stats.bitmap_data, 0);
  1821. atomic_set(&osb->alloc_stats.bg_allocs, 0);
  1822. atomic_set(&osb->alloc_stats.bg_extends, 0);
  1823. /* Copy the blockcheck stats from the superblock probe */
  1824. osb->osb_ecc_stats = *stats;
  1825. ocfs2_init_node_maps(osb);
  1826. snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
  1827. MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
  1828. osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
  1829. if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
  1830. mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
  1831. osb->max_slots);
  1832. status = -EINVAL;
  1833. goto bail;
  1834. }
  1835. ocfs2_orphan_scan_init(osb);
  1836. status = ocfs2_recovery_init(osb);
  1837. if (status) {
  1838. mlog(ML_ERROR, "Unable to initialize recovery state\n");
  1839. mlog_errno(status);
  1840. goto bail;
  1841. }
  1842. init_waitqueue_head(&osb->checkpoint_event);
  1843. osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
  1844. osb->slot_num = OCFS2_INVALID_SLOT;
  1845. osb->s_xattr_inline_size = le16_to_cpu(
  1846. di->id2.i_super.s_xattr_inline_size);
  1847. osb->local_alloc_state = OCFS2_LA_UNUSED;
  1848. osb->local_alloc_bh = NULL;
  1849. INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker);
  1850. init_waitqueue_head(&osb->osb_mount_event);
  1851. status = ocfs2_resmap_init(osb, &osb->osb_la_resmap);
  1852. if (status) {
  1853. mlog_errno(status);
  1854. goto bail;
  1855. }
  1856. osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL);
  1857. if (!osb->vol_label) {
  1858. mlog(ML_ERROR, "unable to alloc vol label\n");
  1859. status = -ENOMEM;
  1860. goto bail;
  1861. }
  1862. osb->slot_recovery_generations =
  1863. kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
  1864. GFP_KERNEL);
  1865. if (!osb->slot_recovery_generations) {
  1866. status = -ENOMEM;
  1867. mlog_errno(status);
  1868. goto bail;
  1869. }
  1870. init_waitqueue_head(&osb->osb_wipe_event);
  1871. osb->osb_orphan_wipes = kcalloc(osb->max_slots,
  1872. sizeof(*osb->osb_orphan_wipes),
  1873. GFP_KERNEL);
  1874. if (!osb->osb_orphan_wipes) {
  1875. status = -ENOMEM;
  1876. mlog_errno(status);
  1877. goto bail;
  1878. }
  1879. osb->osb_rf_lock_tree = RB_ROOT;
  1880. osb->s_feature_compat =
  1881. le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat);
  1882. osb->s_feature_ro_compat =
  1883. le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat);
  1884. osb->s_feature_incompat =
  1885. le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat);
  1886. if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) {
  1887. mlog(ML_ERROR, "couldn't mount because of unsupported "
  1888. "optional features (%x).\n", i);
  1889. status = -EINVAL;
  1890. goto bail;
  1891. }
  1892. if (!(osb->sb->s_flags & MS_RDONLY) &&
  1893. (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) {
  1894. mlog(ML_ERROR, "couldn't mount RDWR because of "
  1895. "unsupported optional features (%x).\n", i);
  1896. status = -EINVAL;
  1897. goto bail;
  1898. }
  1899. if (ocfs2_clusterinfo_valid(osb)) {
  1900. osb->osb_stackflags =
  1901. OCFS2_RAW_SB(di)->s_cluster_info.ci_stackflags;
  1902. strlcpy(osb->osb_cluster_stack,
  1903. OCFS2_RAW_SB(di)->s_cluster_info.ci_stack,
  1904. OCFS2_STACK_LABEL_LEN + 1);
  1905. if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) {
  1906. mlog(ML_ERROR,
  1907. "couldn't mount because of an invalid "
  1908. "cluster stack label (%s) \n",
  1909. osb->osb_cluster_stack);
  1910. status = -EINVAL;
  1911. goto bail;
  1912. }
  1913. strlcpy(osb->osb_cluster_name,
  1914. OCFS2_RAW_SB(di)->s_cluster_info.ci_cluster,
  1915. OCFS2_CLUSTER_NAME_LEN + 1);
  1916. } else {
  1917. /* The empty string is identical with classic tools that
  1918. * don't know about s_cluster_info. */
  1919. osb->osb_cluster_stack[0] = '\0';
  1920. }
  1921. get_random_bytes(&osb->s_next_generation, sizeof(u32));
  1922. /* FIXME
  1923. * This should be done in ocfs2_journal_init(), but unknown
  1924. * ordering issues will cause the filesystem to crash.
  1925. * If anyone wants to figure out what part of the code
  1926. * refers to osb->journal before ocfs2_journal_init() is run,
  1927. * be my guest.
  1928. */
  1929. /* initialize our journal structure */
  1930. journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
  1931. if (!journal) {
  1932. mlog(ML_ERROR, "unable to alloc journal\n");
  1933. status = -ENOMEM;
  1934. goto bail;
  1935. }
  1936. osb->journal = journal;
  1937. journal->j_osb = osb;
  1938. atomic_set(&journal->j_num_trans, 0);
  1939. init_rwsem(&journal->j_trans_barrier);
  1940. init_waitqueue_head(&journal->j_checkpointed);
  1941. spin_lock_init(&journal->j_lock);
  1942. journal->j_trans_id = (unsigned long) 1;
  1943. INIT_LIST_HEAD(&journal->j_la_cleanups);
  1944. INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
  1945. journal->j_state = OCFS2_JOURNAL_FREE;
  1946. INIT_WORK(&osb->dquot_drop_work, ocfs2_drop_dquot_refs);
  1947. init_llist_head(&osb->dquot_drop_list);
  1948. /* get some pseudo constants for clustersize bits */
  1949. osb->s_clustersize_bits =
  1950. le32_to_cpu(di->id2.i_super.s_clustersize_bits);
  1951. osb->s_clustersize = 1 << osb->s_clustersize_bits;
  1952. if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE ||
  1953. osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) {
  1954. mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n",
  1955. osb->s_clustersize);
  1956. status = -EINVAL;
  1957. goto bail;
  1958. }
  1959. total_blocks = ocfs2_clusters_to_blocks(osb->sb,
  1960. le32_to_cpu(di->i_clusters));
  1961. status = generic_check_addressable(osb->sb->s_blocksize_bits,
  1962. total_blocks);
  1963. if (status) {
  1964. mlog(ML_ERROR, "Volume too large "
  1965. "to mount safely on this system");
  1966. status = -EFBIG;
  1967. goto bail;
  1968. }
  1969. if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid,
  1970. sizeof(di->id2.i_super.s_uuid))) {
  1971. mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n");
  1972. status = -ENOMEM;
  1973. goto bail;
  1974. }
  1975. strlcpy(osb->vol_label, di->id2.i_super.s_label,
  1976. OCFS2_MAX_VOL_LABEL_LEN);
  1977. osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno);
  1978. osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno);
  1979. osb->first_cluster_group_blkno =
  1980. le64_to_cpu(di->id2.i_super.s_first_cluster_group);
  1981. osb->fs_generation = le32_to_cpu(di->i_fs_generation);
  1982. osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
  1983. trace_ocfs2_initialize_super(osb->vol_label, osb->uuid_str,
  1984. (unsigned long long)osb->root_blkno,
  1985. (unsigned long long)osb->system_dir_blkno,
  1986. osb->s_clustersize_bits);
  1987. osb->osb_dlm_debug = ocfs2_new_dlm_debug();
  1988. if (!osb->osb_dlm_debug) {
  1989. status = -ENOMEM;
  1990. mlog_errno(status);
  1991. goto bail;
  1992. }
  1993. atomic_set(&osb->vol_state, VOLUME_INIT);
  1994. /* load root, system_dir, and all global system inodes */
  1995. status = ocfs2_init_global_system_inodes(osb);
  1996. if (status < 0) {
  1997. mlog_errno(status);
  1998. goto bail;
  1999. }
  2000. /*
  2001. * global bitmap
  2002. */
  2003. inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE,
  2004. OCFS2_INVALID_SLOT);
  2005. if (!inode) {
  2006. status = -EINVAL;
  2007. mlog_errno(status);
  2008. goto bail;
  2009. }
  2010. osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno;
  2011. osb->osb_clusters_at_boot = OCFS2_I(inode)->ip_clusters;
  2012. iput(inode);
  2013. osb->bitmap_cpg = ocfs2_group_bitmap_size(sb, 0,
  2014. osb->s_feature_incompat) * 8;
  2015. status = ocfs2_init_slot_info(osb);
  2016. if (status < 0) {
  2017. mlog_errno(status);
  2018. goto bail;
  2019. }
  2020. cleancache_init_shared_fs(sb);
  2021. osb->ocfs2_wq = alloc_ordered_workqueue("ocfs2_wq", WQ_MEM_RECLAIM);
  2022. if (!osb->ocfs2_wq) {
  2023. status = -ENOMEM;
  2024. mlog_errno(status);
  2025. }
  2026. bail:
  2027. return status;
  2028. }
  2029. /*
  2030. * will return: -EAGAIN if it is ok to keep searching for superblocks
  2031. * -EINVAL if there is a bad superblock
  2032. * 0 on success
  2033. */
  2034. static int ocfs2_verify_volume(struct ocfs2_dinode *di,
  2035. struct buffer_head *bh,
  2036. u32 blksz,
  2037. struct ocfs2_blockcheck_stats *stats)
  2038. {
  2039. int status = -EAGAIN;
  2040. if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
  2041. strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
  2042. /* We have to do a raw check of the feature here */
  2043. if (le32_to_cpu(di->id2.i_super.s_feature_incompat) &
  2044. OCFS2_FEATURE_INCOMPAT_META_ECC) {
  2045. status = ocfs2_block_check_validate(bh->b_data,
  2046. bh->b_size,
  2047. &di->i_check,
  2048. stats);
  2049. if (status)
  2050. goto out;
  2051. }
  2052. status = -EINVAL;
  2053. if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) {
  2054. mlog(ML_ERROR, "found superblock with incorrect block "
  2055. "size: found %u, should be %u\n",
  2056. 1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits),
  2057. blksz);
  2058. } else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) !=
  2059. OCFS2_MAJOR_REV_LEVEL ||
  2060. le16_to_cpu(di->id2.i_super.s_minor_rev_level) !=
  2061. OCFS2_MINOR_REV_LEVEL) {
  2062. mlog(ML_ERROR, "found superblock with bad version: "
  2063. "found %u.%u, should be %u.%u\n",
  2064. le16_to_cpu(di->id2.i_super.s_major_rev_level),
  2065. le16_to_cpu(di->id2.i_super.s_minor_rev_level),
  2066. OCFS2_MAJOR_REV_LEVEL,
  2067. OCFS2_MINOR_REV_LEVEL);
  2068. } else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) {
  2069. mlog(ML_ERROR, "bad block number on superblock: "
  2070. "found %llu, should be %llu\n",
  2071. (unsigned long long)le64_to_cpu(di->i_blkno),
  2072. (unsigned long long)bh->b_blocknr);
  2073. } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 ||
  2074. le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) {
  2075. mlog(ML_ERROR, "bad cluster size found: %u\n",
  2076. 1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits));
  2077. } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) {
  2078. mlog(ML_ERROR, "bad root_blkno: 0\n");
  2079. } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) {
  2080. mlog(ML_ERROR, "bad system_dir_blkno: 0\n");
  2081. } else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) {
  2082. mlog(ML_ERROR,
  2083. "Superblock slots found greater than file system "
  2084. "maximum: found %u, max %u\n",
  2085. le16_to_cpu(di->id2.i_super.s_max_slots),
  2086. OCFS2_MAX_SLOTS);
  2087. } else {
  2088. /* found it! */
  2089. status = 0;
  2090. }
  2091. }
  2092. out:
  2093. if (status && status != -EAGAIN)
  2094. mlog_errno(status);
  2095. return status;
  2096. }
  2097. static int ocfs2_check_volume(struct ocfs2_super *osb)
  2098. {
  2099. int status;
  2100. int dirty;
  2101. int local;
  2102. struct ocfs2_dinode *local_alloc = NULL; /* only used if we
  2103. * recover
  2104. * ourselves. */
  2105. /* Init our journal object. */
  2106. status = ocfs2_journal_init(osb->journal, &dirty);
  2107. if (status < 0) {
  2108. mlog(ML_ERROR, "Could not initialize journal!\n");
  2109. goto finally;
  2110. }
  2111. /* Now that journal has been initialized, check to make sure
  2112. entire volume is addressable. */
  2113. status = ocfs2_journal_addressable(osb);
  2114. if (status)
  2115. goto finally;
  2116. /* If the journal was unmounted cleanly then we don't want to
  2117. * recover anything. Otherwise, journal_load will do that
  2118. * dirty work for us :) */
  2119. if (!dirty) {
  2120. status = ocfs2_journal_wipe(osb->journal, 0);
  2121. if (status < 0) {
  2122. mlog_errno(status);
  2123. goto finally;
  2124. }
  2125. } else {
  2126. printk(KERN_NOTICE "ocfs2: File system on device (%s) was not "
  2127. "unmounted cleanly, recovering it.\n", osb->dev_str);
  2128. }
  2129. local = ocfs2_mount_local(osb);
  2130. /* will play back anything left in the journal. */
  2131. status = ocfs2_journal_load(osb->journal, local, dirty);
  2132. if (status < 0) {
  2133. mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status);
  2134. goto finally;
  2135. }
  2136. if (osb->s_mount_opt & OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT)
  2137. jbd2_journal_set_features(osb->journal->j_journal,
  2138. JBD2_FEATURE_COMPAT_CHECKSUM, 0,
  2139. JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
  2140. else
  2141. jbd2_journal_clear_features(osb->journal->j_journal,
  2142. JBD2_FEATURE_COMPAT_CHECKSUM, 0,
  2143. JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
  2144. if (dirty) {
  2145. /* recover my local alloc if we didn't unmount cleanly. */
  2146. status = ocfs2_begin_local_alloc_recovery(osb,
  2147. osb->slot_num,
  2148. &local_alloc);
  2149. if (status < 0) {
  2150. mlog_errno(status);
  2151. goto finally;
  2152. }
  2153. /* we complete the recovery process after we've marked
  2154. * ourselves as mounted. */
  2155. }
  2156. status = ocfs2_load_local_alloc(osb);
  2157. if (status < 0) {
  2158. mlog_errno(status);
  2159. goto finally;
  2160. }
  2161. if (dirty) {
  2162. /* Recovery will be completed after we've mounted the
  2163. * rest of the volume. */
  2164. osb->dirty = 1;
  2165. osb->local_alloc_copy = local_alloc;
  2166. local_alloc = NULL;
  2167. }
  2168. /* go through each journal, trylock it and if you get the
  2169. * lock, and it's marked as dirty, set the bit in the recover
  2170. * map and launch a recovery thread for it. */
  2171. status = ocfs2_mark_dead_nodes(osb);
  2172. if (status < 0) {
  2173. mlog_errno(status);
  2174. goto finally;
  2175. }
  2176. status = ocfs2_compute_replay_slots(osb);
  2177. if (status < 0)
  2178. mlog_errno(status);
  2179. finally:
  2180. kfree(local_alloc);
  2181. if (status)
  2182. mlog_errno(status);
  2183. return status;
  2184. }
  2185. /*
  2186. * The routine gets called from dismount or close whenever a dismount on
  2187. * volume is requested and the osb open count becomes 1.
  2188. * It will remove the osb from the global list and also free up all the
  2189. * initialized resources and fileobject.
  2190. */
  2191. static void ocfs2_delete_osb(struct ocfs2_super *osb)
  2192. {
  2193. /* This function assumes that the caller has the main osb resource */
  2194. /* ocfs2_initializer_super have already created this workqueue */
  2195. if (osb->ocfs2_wq) {
  2196. flush_workqueue(osb->ocfs2_wq);
  2197. destroy_workqueue(osb->ocfs2_wq);
  2198. }
  2199. ocfs2_free_slot_info(osb);
  2200. kfree(osb->osb_orphan_wipes);
  2201. kfree(osb->slot_recovery_generations);
  2202. /* FIXME
  2203. * This belongs in journal shutdown, but because we have to
  2204. * allocate osb->journal at the start of ocfs2_initialize_osb(),
  2205. * we free it here.
  2206. */
  2207. kfree(osb->journal);
  2208. kfree(osb->local_alloc_copy);
  2209. kfree(osb->uuid_str);
  2210. kfree(osb->vol_label);
  2211. ocfs2_put_dlm_debug(osb->osb_dlm_debug);
  2212. memset(osb, 0, sizeof(struct ocfs2_super));
  2213. }
  2214. /* Depending on the mount option passed, perform one of the following:
  2215. * Put OCFS2 into a readonly state (default)
  2216. * Return EIO so that only the process errs
  2217. * Fix the error as if fsck.ocfs2 -y
  2218. * panic
  2219. */
  2220. static int ocfs2_handle_error(struct super_block *sb)
  2221. {
  2222. struct ocfs2_super *osb = OCFS2_SB(sb);
  2223. int rv = 0;
  2224. ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS);
  2225. pr_crit("On-disk corruption discovered. "
  2226. "Please run fsck.ocfs2 once the filesystem is unmounted.\n");
  2227. if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC) {
  2228. panic("OCFS2: (device %s): panic forced after error\n",
  2229. sb->s_id);
  2230. } else if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_CONT) {
  2231. pr_crit("OCFS2: Returning error to the calling process.\n");
  2232. rv = -EIO;
  2233. } else { /* default option */
  2234. rv = -EROFS;
  2235. if (sb->s_flags & MS_RDONLY &&
  2236. (ocfs2_is_soft_readonly(osb) ||
  2237. ocfs2_is_hard_readonly(osb)))
  2238. return rv;
  2239. pr_crit("OCFS2: File system is now read-only.\n");
  2240. sb->s_flags |= MS_RDONLY;
  2241. ocfs2_set_ro_flag(osb, 0);
  2242. }
  2243. return rv;
  2244. }
  2245. int __ocfs2_error(struct super_block *sb, const char *function,
  2246. const char *fmt, ...)
  2247. {
  2248. struct va_format vaf;
  2249. va_list args;
  2250. va_start(args, fmt);
  2251. vaf.fmt = fmt;
  2252. vaf.va = &args;
  2253. /* Not using mlog here because we want to show the actual
  2254. * function the error came from. */
  2255. printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %pV",
  2256. sb->s_id, function, &vaf);
  2257. va_end(args);
  2258. return ocfs2_handle_error(sb);
  2259. }
  2260. /* Handle critical errors. This is intentionally more drastic than
  2261. * ocfs2_handle_error, so we only use for things like journal errors,
  2262. * etc. */
  2263. void __ocfs2_abort(struct super_block *sb, const char *function,
  2264. const char *fmt, ...)
  2265. {
  2266. struct va_format vaf;
  2267. va_list args;
  2268. va_start(args, fmt);
  2269. vaf.fmt = fmt;
  2270. vaf.va = &args;
  2271. printk(KERN_CRIT "OCFS2: abort (device %s): %s: %pV",
  2272. sb->s_id, function, &vaf);
  2273. va_end(args);
  2274. /* We don't have the cluster support yet to go straight to
  2275. * hard readonly in here. Until then, we want to keep
  2276. * ocfs2_abort() so that we can at least mark critical
  2277. * errors.
  2278. *
  2279. * TODO: This should abort the journal and alert other nodes
  2280. * that our slot needs recovery. */
  2281. /* Force a panic(). This stinks, but it's better than letting
  2282. * things continue without having a proper hard readonly
  2283. * here. */
  2284. if (!ocfs2_mount_local(OCFS2_SB(sb)))
  2285. OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
  2286. ocfs2_handle_error(sb);
  2287. }
  2288. /*
  2289. * Void signal blockers, because in-kernel sigprocmask() only fails
  2290. * when SIG_* is wrong.
  2291. */
  2292. void ocfs2_block_signals(sigset_t *oldset)
  2293. {
  2294. int rc;
  2295. sigset_t blocked;
  2296. sigfillset(&blocked);
  2297. rc = sigprocmask(SIG_BLOCK, &blocked, oldset);
  2298. BUG_ON(rc);
  2299. }
  2300. void ocfs2_unblock_signals(sigset_t *oldset)
  2301. {
  2302. int rc = sigprocmask(SIG_SETMASK, oldset, NULL);
  2303. BUG_ON(rc);
  2304. }
  2305. module_init(ocfs2_init);
  2306. module_exit(ocfs2_exit);