super.c 70 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671
  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. #include <linux/signal.h>
  45. #define CREATE_TRACE_POINTS
  46. #include "ocfs2_trace.h"
  47. #include <cluster/masklog.h>
  48. #include "ocfs2.h"
  49. /* this should be the only file to include a version 1 header */
  50. #include "ocfs1_fs_compat.h"
  51. #include "alloc.h"
  52. #include "aops.h"
  53. #include "blockcheck.h"
  54. #include "dlmglue.h"
  55. #include "export.h"
  56. #include "extent_map.h"
  57. #include "heartbeat.h"
  58. #include "inode.h"
  59. #include "journal.h"
  60. #include "localalloc.h"
  61. #include "namei.h"
  62. #include "slot_map.h"
  63. #include "super.h"
  64. #include "sysfile.h"
  65. #include "uptodate.h"
  66. #include "xattr.h"
  67. #include "quota.h"
  68. #include "refcounttree.h"
  69. #include "suballoc.h"
  70. #include "buffer_head_io.h"
  71. #include "filecheck.h"
  72. static struct kmem_cache *ocfs2_inode_cachep;
  73. struct kmem_cache *ocfs2_dquot_cachep;
  74. struct kmem_cache *ocfs2_qf_chunk_cachep;
  75. static struct dentry *ocfs2_debugfs_root;
  76. MODULE_AUTHOR("Oracle");
  77. MODULE_LICENSE("GPL");
  78. MODULE_DESCRIPTION("OCFS2 cluster file system");
  79. struct mount_options
  80. {
  81. unsigned long commit_interval;
  82. unsigned long mount_opt;
  83. unsigned int atime_quantum;
  84. signed short slot;
  85. int localalloc_opt;
  86. unsigned int resv_level;
  87. int dir_resv_level;
  88. char cluster_stack[OCFS2_STACK_LABEL_LEN + 1];
  89. };
  90. static int ocfs2_parse_options(struct super_block *sb, char *options,
  91. struct mount_options *mopt,
  92. int is_remount);
  93. static int ocfs2_check_set_options(struct super_block *sb,
  94. struct mount_options *options);
  95. static int ocfs2_show_options(struct seq_file *s, struct dentry *root);
  96. static void ocfs2_put_super(struct super_block *sb);
  97. static int ocfs2_mount_volume(struct super_block *sb);
  98. static int ocfs2_remount(struct super_block *sb, int *flags, char *data);
  99. static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err);
  100. static int ocfs2_initialize_mem_caches(void);
  101. static void ocfs2_free_mem_caches(void);
  102. static void ocfs2_delete_osb(struct ocfs2_super *osb);
  103. static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf);
  104. static int ocfs2_sync_fs(struct super_block *sb, int wait);
  105. static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb);
  106. static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb);
  107. static void ocfs2_release_system_inodes(struct ocfs2_super *osb);
  108. static int ocfs2_check_volume(struct ocfs2_super *osb);
  109. static int ocfs2_verify_volume(struct ocfs2_dinode *di,
  110. struct buffer_head *bh,
  111. u32 sectsize,
  112. struct ocfs2_blockcheck_stats *stats);
  113. static int ocfs2_initialize_super(struct super_block *sb,
  114. struct buffer_head *bh,
  115. int sector_size,
  116. struct ocfs2_blockcheck_stats *stats);
  117. static int ocfs2_get_sector(struct super_block *sb,
  118. struct buffer_head **bh,
  119. int block,
  120. int sect_size);
  121. static struct inode *ocfs2_alloc_inode(struct super_block *sb);
  122. static void ocfs2_destroy_inode(struct inode *inode);
  123. static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend);
  124. static int ocfs2_enable_quotas(struct ocfs2_super *osb);
  125. static void ocfs2_disable_quotas(struct ocfs2_super *osb);
  126. static struct dquot **ocfs2_get_dquots(struct inode *inode)
  127. {
  128. return OCFS2_I(inode)->i_dquot;
  129. }
  130. static const struct super_operations ocfs2_sops = {
  131. .statfs = ocfs2_statfs,
  132. .alloc_inode = ocfs2_alloc_inode,
  133. .destroy_inode = ocfs2_destroy_inode,
  134. .drop_inode = ocfs2_drop_inode,
  135. .evict_inode = ocfs2_evict_inode,
  136. .sync_fs = ocfs2_sync_fs,
  137. .put_super = ocfs2_put_super,
  138. .remount_fs = ocfs2_remount,
  139. .show_options = ocfs2_show_options,
  140. .quota_read = ocfs2_quota_read,
  141. .quota_write = ocfs2_quota_write,
  142. .get_dquots = ocfs2_get_dquots,
  143. };
  144. enum {
  145. Opt_barrier,
  146. Opt_err_panic,
  147. Opt_err_ro,
  148. Opt_intr,
  149. Opt_nointr,
  150. Opt_hb_none,
  151. Opt_hb_local,
  152. Opt_hb_global,
  153. Opt_data_ordered,
  154. Opt_data_writeback,
  155. Opt_atime_quantum,
  156. Opt_slot,
  157. Opt_commit,
  158. Opt_localalloc,
  159. Opt_localflocks,
  160. Opt_stack,
  161. Opt_user_xattr,
  162. Opt_nouser_xattr,
  163. Opt_inode64,
  164. Opt_acl,
  165. Opt_noacl,
  166. Opt_usrquota,
  167. Opt_grpquota,
  168. Opt_coherency_buffered,
  169. Opt_coherency_full,
  170. Opt_resv_level,
  171. Opt_dir_resv_level,
  172. Opt_journal_async_commit,
  173. Opt_err_cont,
  174. Opt_err,
  175. };
  176. static const match_table_t tokens = {
  177. {Opt_barrier, "barrier=%u"},
  178. {Opt_err_panic, "errors=panic"},
  179. {Opt_err_ro, "errors=remount-ro"},
  180. {Opt_intr, "intr"},
  181. {Opt_nointr, "nointr"},
  182. {Opt_hb_none, OCFS2_HB_NONE},
  183. {Opt_hb_local, OCFS2_HB_LOCAL},
  184. {Opt_hb_global, OCFS2_HB_GLOBAL},
  185. {Opt_data_ordered, "data=ordered"},
  186. {Opt_data_writeback, "data=writeback"},
  187. {Opt_atime_quantum, "atime_quantum=%u"},
  188. {Opt_slot, "preferred_slot=%u"},
  189. {Opt_commit, "commit=%u"},
  190. {Opt_localalloc, "localalloc=%d"},
  191. {Opt_localflocks, "localflocks"},
  192. {Opt_stack, "cluster_stack=%s"},
  193. {Opt_user_xattr, "user_xattr"},
  194. {Opt_nouser_xattr, "nouser_xattr"},
  195. {Opt_inode64, "inode64"},
  196. {Opt_acl, "acl"},
  197. {Opt_noacl, "noacl"},
  198. {Opt_usrquota, "usrquota"},
  199. {Opt_grpquota, "grpquota"},
  200. {Opt_coherency_buffered, "coherency=buffered"},
  201. {Opt_coherency_full, "coherency=full"},
  202. {Opt_resv_level, "resv_level=%u"},
  203. {Opt_dir_resv_level, "dir_resv_level=%u"},
  204. {Opt_journal_async_commit, "journal_async_commit"},
  205. {Opt_err_cont, "errors=continue"},
  206. {Opt_err, NULL}
  207. };
  208. #ifdef CONFIG_DEBUG_FS
  209. static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
  210. {
  211. struct ocfs2_cluster_connection *cconn = osb->cconn;
  212. struct ocfs2_recovery_map *rm = osb->recovery_map;
  213. struct ocfs2_orphan_scan *os = &osb->osb_orphan_scan;
  214. int i, out = 0;
  215. unsigned long flags;
  216. out += snprintf(buf + out, len - out,
  217. "%10s => Id: %-s Uuid: %-s Gen: 0x%X Label: %-s\n",
  218. "Device", osb->dev_str, osb->uuid_str,
  219. osb->fs_generation, osb->vol_label);
  220. out += snprintf(buf + out, len - out,
  221. "%10s => State: %d Flags: 0x%lX\n", "Volume",
  222. atomic_read(&osb->vol_state), osb->osb_flags);
  223. out += snprintf(buf + out, len - out,
  224. "%10s => Block: %lu Cluster: %d\n", "Sizes",
  225. osb->sb->s_blocksize, osb->s_clustersize);
  226. out += snprintf(buf + out, len - out,
  227. "%10s => Compat: 0x%X Incompat: 0x%X "
  228. "ROcompat: 0x%X\n",
  229. "Features", osb->s_feature_compat,
  230. osb->s_feature_incompat, osb->s_feature_ro_compat);
  231. out += snprintf(buf + out, len - out,
  232. "%10s => Opts: 0x%lX AtimeQuanta: %u\n", "Mount",
  233. osb->s_mount_opt, osb->s_atime_quantum);
  234. if (cconn) {
  235. out += snprintf(buf + out, len - out,
  236. "%10s => Stack: %s Name: %*s "
  237. "Version: %d.%d\n", "Cluster",
  238. (*osb->osb_cluster_stack == '\0' ?
  239. "o2cb" : osb->osb_cluster_stack),
  240. cconn->cc_namelen, cconn->cc_name,
  241. cconn->cc_version.pv_major,
  242. cconn->cc_version.pv_minor);
  243. }
  244. spin_lock_irqsave(&osb->dc_task_lock, flags);
  245. out += snprintf(buf + out, len - out,
  246. "%10s => Pid: %d Count: %lu WakeSeq: %lu "
  247. "WorkSeq: %lu\n", "DownCnvt",
  248. (osb->dc_task ? task_pid_nr(osb->dc_task) : -1),
  249. osb->blocked_lock_count, osb->dc_wake_sequence,
  250. osb->dc_work_sequence);
  251. spin_unlock_irqrestore(&osb->dc_task_lock, flags);
  252. spin_lock(&osb->osb_lock);
  253. out += snprintf(buf + out, len - out, "%10s => Pid: %d Nodes:",
  254. "Recovery",
  255. (osb->recovery_thread_task ?
  256. task_pid_nr(osb->recovery_thread_task) : -1));
  257. if (rm->rm_used == 0)
  258. out += snprintf(buf + out, len - out, " None\n");
  259. else {
  260. for (i = 0; i < rm->rm_used; i++)
  261. out += snprintf(buf + out, len - out, " %d",
  262. rm->rm_entries[i]);
  263. out += snprintf(buf + out, len - out, "\n");
  264. }
  265. spin_unlock(&osb->osb_lock);
  266. out += snprintf(buf + out, len - out,
  267. "%10s => Pid: %d Interval: %lu\n", "Commit",
  268. (osb->commit_task ? task_pid_nr(osb->commit_task) : -1),
  269. osb->osb_commit_interval);
  270. out += snprintf(buf + out, len - out,
  271. "%10s => State: %d TxnId: %lu NumTxns: %d\n",
  272. "Journal", osb->journal->j_state,
  273. osb->journal->j_trans_id,
  274. atomic_read(&osb->journal->j_num_trans));
  275. out += snprintf(buf + out, len - out,
  276. "%10s => GlobalAllocs: %d LocalAllocs: %d "
  277. "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
  278. "Stats",
  279. atomic_read(&osb->alloc_stats.bitmap_data),
  280. atomic_read(&osb->alloc_stats.local_data),
  281. atomic_read(&osb->alloc_stats.bg_allocs),
  282. atomic_read(&osb->alloc_stats.moves),
  283. atomic_read(&osb->alloc_stats.bg_extends));
  284. out += snprintf(buf + out, len - out,
  285. "%10s => State: %u Descriptor: %llu Size: %u bits "
  286. "Default: %u bits\n",
  287. "LocalAlloc", osb->local_alloc_state,
  288. (unsigned long long)osb->la_last_gd,
  289. osb->local_alloc_bits, osb->local_alloc_default_bits);
  290. spin_lock(&osb->osb_lock);
  291. out += snprintf(buf + out, len - out,
  292. "%10s => InodeSlot: %d StolenInodes: %d, "
  293. "MetaSlot: %d StolenMeta: %d\n", "Steal",
  294. osb->s_inode_steal_slot,
  295. atomic_read(&osb->s_num_inodes_stolen),
  296. osb->s_meta_steal_slot,
  297. atomic_read(&osb->s_num_meta_stolen));
  298. spin_unlock(&osb->osb_lock);
  299. out += snprintf(buf + out, len - out, "OrphanScan => ");
  300. out += snprintf(buf + out, len - out, "Local: %u Global: %u ",
  301. os->os_count, os->os_seqno);
  302. out += snprintf(buf + out, len - out, " Last Scan: ");
  303. if (atomic_read(&os->os_state) == ORPHAN_SCAN_INACTIVE)
  304. out += snprintf(buf + out, len - out, "Disabled\n");
  305. else
  306. out += snprintf(buf + out, len - out, "%lu seconds ago\n",
  307. (unsigned long)(ktime_get_seconds() - os->os_scantime));
  308. out += snprintf(buf + out, len - out, "%10s => %3s %10s\n",
  309. "Slots", "Num", "RecoGen");
  310. for (i = 0; i < osb->max_slots; ++i) {
  311. out += snprintf(buf + out, len - out,
  312. "%10s %c %3d %10d\n",
  313. " ",
  314. (i == osb->slot_num ? '*' : ' '),
  315. i, osb->slot_recovery_generations[i]);
  316. }
  317. return out;
  318. }
  319. static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
  320. {
  321. struct ocfs2_super *osb = inode->i_private;
  322. char *buf = NULL;
  323. buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  324. if (!buf)
  325. goto bail;
  326. i_size_write(inode, ocfs2_osb_dump(osb, buf, PAGE_SIZE));
  327. file->private_data = buf;
  328. return 0;
  329. bail:
  330. return -ENOMEM;
  331. }
  332. static int ocfs2_debug_release(struct inode *inode, struct file *file)
  333. {
  334. kfree(file->private_data);
  335. return 0;
  336. }
  337. static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
  338. size_t nbytes, loff_t *ppos)
  339. {
  340. return simple_read_from_buffer(buf, nbytes, ppos, file->private_data,
  341. i_size_read(file->f_mapping->host));
  342. }
  343. #else
  344. static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
  345. {
  346. return 0;
  347. }
  348. static int ocfs2_debug_release(struct inode *inode, struct file *file)
  349. {
  350. return 0;
  351. }
  352. static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
  353. size_t nbytes, loff_t *ppos)
  354. {
  355. return 0;
  356. }
  357. #endif /* CONFIG_DEBUG_FS */
  358. static const struct file_operations ocfs2_osb_debug_fops = {
  359. .open = ocfs2_osb_debug_open,
  360. .release = ocfs2_debug_release,
  361. .read = ocfs2_debug_read,
  362. .llseek = generic_file_llseek,
  363. };
  364. static int ocfs2_sync_fs(struct super_block *sb, int wait)
  365. {
  366. int status;
  367. tid_t target;
  368. struct ocfs2_super *osb = OCFS2_SB(sb);
  369. if (ocfs2_is_hard_readonly(osb))
  370. return -EROFS;
  371. if (wait) {
  372. status = ocfs2_flush_truncate_log(osb);
  373. if (status < 0)
  374. mlog_errno(status);
  375. } else {
  376. ocfs2_schedule_truncate_log_flush(osb, 0);
  377. }
  378. if (jbd2_journal_start_commit(osb->journal->j_journal,
  379. &target)) {
  380. if (wait)
  381. jbd2_log_wait_commit(osb->journal->j_journal,
  382. target);
  383. }
  384. return 0;
  385. }
  386. static int ocfs2_need_system_inode(struct ocfs2_super *osb, int ino)
  387. {
  388. if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_USRQUOTA)
  389. && (ino == USER_QUOTA_SYSTEM_INODE
  390. || ino == LOCAL_USER_QUOTA_SYSTEM_INODE))
  391. return 0;
  392. if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
  393. && (ino == GROUP_QUOTA_SYSTEM_INODE
  394. || ino == LOCAL_GROUP_QUOTA_SYSTEM_INODE))
  395. return 0;
  396. return 1;
  397. }
  398. static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb)
  399. {
  400. struct inode *new = NULL;
  401. int status = 0;
  402. int i;
  403. new = ocfs2_iget(osb, osb->root_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
  404. if (IS_ERR(new)) {
  405. status = PTR_ERR(new);
  406. mlog_errno(status);
  407. goto bail;
  408. }
  409. osb->root_inode = new;
  410. new = ocfs2_iget(osb, osb->system_dir_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
  411. if (IS_ERR(new)) {
  412. status = PTR_ERR(new);
  413. mlog_errno(status);
  414. goto bail;
  415. }
  416. osb->sys_root_inode = new;
  417. for (i = OCFS2_FIRST_ONLINE_SYSTEM_INODE;
  418. i <= OCFS2_LAST_GLOBAL_SYSTEM_INODE; i++) {
  419. if (!ocfs2_need_system_inode(osb, i))
  420. continue;
  421. new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
  422. if (!new) {
  423. ocfs2_release_system_inodes(osb);
  424. status = ocfs2_is_soft_readonly(osb) ? -EROFS : -EINVAL;
  425. mlog_errno(status);
  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 = ocfs2_is_soft_readonly(osb) ? -EROFS : -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 ((bool)(*flags & SB_RDONLY) != sb_rdonly(sb)) {
  597. /* Disable quota accounting before remounting RO */
  598. if (*flags & SB_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 & SB_RDONLY) {
  612. sb->s_flags |= SB_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 &= ~SB_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 & SB_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 |= SB_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 & ~SB_POSIXACL) |
  662. ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ?
  663. SB_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 & ~(SB_POSIXACL | SB_NOSEC)) |
  943. ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? SB_POSIXACL : 0);
  944. /* Hard readonly mode only if: bdev_read_only, SB_RDONLY,
  945. * heartbeat=none */
  946. if (bdev_read_only(sb->s_bdev)) {
  947. if (!sb_rdonly(sb)) {
  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_rdonly(sb))
  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. osb->osb_dev_kset = kset_create_and_add(sb->s_id, NULL,
  1031. &ocfs2_kset->kobj);
  1032. if (!osb->osb_dev_kset) {
  1033. status = -ENOMEM;
  1034. mlog(ML_ERROR, "Unable to create device kset %s.\n", sb->s_id);
  1035. goto read_super_error;
  1036. }
  1037. /* Create filecheck sysfs related directories/files at
  1038. * /sys/fs/ocfs2/<devname>/filecheck */
  1039. if (ocfs2_filecheck_create_sysfs(osb)) {
  1040. status = -ENOMEM;
  1041. mlog(ML_ERROR, "Unable to create filecheck sysfs directory at "
  1042. "/sys/fs/ocfs2/%s/filecheck.\n", sb->s_id);
  1043. goto read_super_error;
  1044. }
  1045. if (ocfs2_mount_local(osb))
  1046. snprintf(nodestr, sizeof(nodestr), "local");
  1047. else
  1048. snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
  1049. printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
  1050. "with %s data mode.\n",
  1051. osb->dev_str, nodestr, osb->slot_num,
  1052. osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
  1053. "ordered");
  1054. atomic_set(&osb->vol_state, VOLUME_MOUNTED);
  1055. wake_up(&osb->osb_mount_event);
  1056. /* Now we can initialize quotas because we can afford to wait
  1057. * for cluster locks recovery now. That also means that truncation
  1058. * log recovery can happen but that waits for proper quota setup */
  1059. if (!sb_rdonly(sb)) {
  1060. status = ocfs2_enable_quotas(osb);
  1061. if (status < 0) {
  1062. /* We have to err-out specially here because
  1063. * s_root is already set */
  1064. mlog_errno(status);
  1065. atomic_set(&osb->vol_state, VOLUME_DISABLED);
  1066. wake_up(&osb->osb_mount_event);
  1067. return status;
  1068. }
  1069. }
  1070. ocfs2_complete_quota_recovery(osb);
  1071. /* Now we wake up again for processes waiting for quotas */
  1072. atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS);
  1073. wake_up(&osb->osb_mount_event);
  1074. /* Start this when the mount is almost sure of being successful */
  1075. ocfs2_orphan_scan_start(osb);
  1076. return status;
  1077. read_super_error:
  1078. brelse(bh);
  1079. if (status)
  1080. mlog_errno(status);
  1081. if (osb) {
  1082. atomic_set(&osb->vol_state, VOLUME_DISABLED);
  1083. wake_up(&osb->osb_mount_event);
  1084. ocfs2_dismount_volume(sb, 1);
  1085. }
  1086. return status;
  1087. }
  1088. static struct dentry *ocfs2_mount(struct file_system_type *fs_type,
  1089. int flags,
  1090. const char *dev_name,
  1091. void *data)
  1092. {
  1093. return mount_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super);
  1094. }
  1095. static struct file_system_type ocfs2_fs_type = {
  1096. .owner = THIS_MODULE,
  1097. .name = "ocfs2",
  1098. .mount = ocfs2_mount,
  1099. .kill_sb = kill_block_super,
  1100. .fs_flags = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE,
  1101. .next = NULL
  1102. };
  1103. MODULE_ALIAS_FS("ocfs2");
  1104. static int ocfs2_check_set_options(struct super_block *sb,
  1105. struct mount_options *options)
  1106. {
  1107. if (options->mount_opt & OCFS2_MOUNT_USRQUOTA &&
  1108. !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
  1109. OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
  1110. mlog(ML_ERROR, "User quotas were requested, but this "
  1111. "filesystem does not have the feature enabled.\n");
  1112. return 0;
  1113. }
  1114. if (options->mount_opt & OCFS2_MOUNT_GRPQUOTA &&
  1115. !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
  1116. OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
  1117. mlog(ML_ERROR, "Group quotas were requested, but this "
  1118. "filesystem does not have the feature enabled.\n");
  1119. return 0;
  1120. }
  1121. if (options->mount_opt & OCFS2_MOUNT_POSIX_ACL &&
  1122. !OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR)) {
  1123. mlog(ML_ERROR, "ACL support requested but extended attributes "
  1124. "feature is not enabled\n");
  1125. return 0;
  1126. }
  1127. /* No ACL setting specified? Use XATTR feature... */
  1128. if (!(options->mount_opt & (OCFS2_MOUNT_POSIX_ACL |
  1129. OCFS2_MOUNT_NO_POSIX_ACL))) {
  1130. if (OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR))
  1131. options->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
  1132. else
  1133. options->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
  1134. }
  1135. return 1;
  1136. }
  1137. static int ocfs2_parse_options(struct super_block *sb,
  1138. char *options,
  1139. struct mount_options *mopt,
  1140. int is_remount)
  1141. {
  1142. int status, user_stack = 0;
  1143. char *p;
  1144. u32 tmp;
  1145. int token, option;
  1146. substring_t args[MAX_OPT_ARGS];
  1147. trace_ocfs2_parse_options(is_remount, options ? options : "(none)");
  1148. mopt->commit_interval = 0;
  1149. mopt->mount_opt = OCFS2_MOUNT_NOINTR;
  1150. mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
  1151. mopt->slot = OCFS2_INVALID_SLOT;
  1152. mopt->localalloc_opt = -1;
  1153. mopt->cluster_stack[0] = '\0';
  1154. mopt->resv_level = OCFS2_DEFAULT_RESV_LEVEL;
  1155. mopt->dir_resv_level = -1;
  1156. if (!options) {
  1157. status = 1;
  1158. goto bail;
  1159. }
  1160. while ((p = strsep(&options, ",")) != NULL) {
  1161. if (!*p)
  1162. continue;
  1163. token = match_token(p, tokens, args);
  1164. switch (token) {
  1165. case Opt_hb_local:
  1166. mopt->mount_opt |= OCFS2_MOUNT_HB_LOCAL;
  1167. break;
  1168. case Opt_hb_none:
  1169. mopt->mount_opt |= OCFS2_MOUNT_HB_NONE;
  1170. break;
  1171. case Opt_hb_global:
  1172. mopt->mount_opt |= OCFS2_MOUNT_HB_GLOBAL;
  1173. break;
  1174. case Opt_barrier:
  1175. if (match_int(&args[0], &option)) {
  1176. status = 0;
  1177. goto bail;
  1178. }
  1179. if (option)
  1180. mopt->mount_opt |= OCFS2_MOUNT_BARRIER;
  1181. else
  1182. mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER;
  1183. break;
  1184. case Opt_intr:
  1185. mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR;
  1186. break;
  1187. case Opt_nointr:
  1188. mopt->mount_opt |= OCFS2_MOUNT_NOINTR;
  1189. break;
  1190. case Opt_err_panic:
  1191. mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_CONT;
  1192. mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_ROFS;
  1193. mopt->mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
  1194. break;
  1195. case Opt_err_ro:
  1196. mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_CONT;
  1197. mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
  1198. mopt->mount_opt |= OCFS2_MOUNT_ERRORS_ROFS;
  1199. break;
  1200. case Opt_err_cont:
  1201. mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_ROFS;
  1202. mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
  1203. mopt->mount_opt |= OCFS2_MOUNT_ERRORS_CONT;
  1204. break;
  1205. case Opt_data_ordered:
  1206. mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK;
  1207. break;
  1208. case Opt_data_writeback:
  1209. mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
  1210. break;
  1211. case Opt_user_xattr:
  1212. mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
  1213. break;
  1214. case Opt_nouser_xattr:
  1215. mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
  1216. break;
  1217. case Opt_atime_quantum:
  1218. if (match_int(&args[0], &option)) {
  1219. status = 0;
  1220. goto bail;
  1221. }
  1222. if (option >= 0)
  1223. mopt->atime_quantum = option;
  1224. break;
  1225. case Opt_slot:
  1226. if (match_int(&args[0], &option)) {
  1227. status = 0;
  1228. goto bail;
  1229. }
  1230. if (option)
  1231. mopt->slot = (s16)option;
  1232. break;
  1233. case Opt_commit:
  1234. if (match_int(&args[0], &option)) {
  1235. status = 0;
  1236. goto bail;
  1237. }
  1238. if (option < 0)
  1239. return 0;
  1240. if (option == 0)
  1241. option = JBD2_DEFAULT_MAX_COMMIT_AGE;
  1242. mopt->commit_interval = HZ * option;
  1243. break;
  1244. case Opt_localalloc:
  1245. if (match_int(&args[0], &option)) {
  1246. status = 0;
  1247. goto bail;
  1248. }
  1249. if (option >= 0)
  1250. mopt->localalloc_opt = option;
  1251. break;
  1252. case Opt_localflocks:
  1253. /*
  1254. * Changing this during remount could race
  1255. * flock() requests, or "unbalance" existing
  1256. * ones (e.g., a lock is taken in one mode but
  1257. * dropped in the other). If users care enough
  1258. * to flip locking modes during remount, we
  1259. * could add a "local" flag to individual
  1260. * flock structures for proper tracking of
  1261. * state.
  1262. */
  1263. if (!is_remount)
  1264. mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
  1265. break;
  1266. case Opt_stack:
  1267. /* Check both that the option we were passed
  1268. * is of the right length and that it is a proper
  1269. * string of the right length.
  1270. */
  1271. if (((args[0].to - args[0].from) !=
  1272. OCFS2_STACK_LABEL_LEN) ||
  1273. (strnlen(args[0].from,
  1274. OCFS2_STACK_LABEL_LEN) !=
  1275. OCFS2_STACK_LABEL_LEN)) {
  1276. mlog(ML_ERROR,
  1277. "Invalid cluster_stack option\n");
  1278. status = 0;
  1279. goto bail;
  1280. }
  1281. memcpy(mopt->cluster_stack, args[0].from,
  1282. OCFS2_STACK_LABEL_LEN);
  1283. mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
  1284. /*
  1285. * Open code the memcmp here as we don't have
  1286. * an osb to pass to
  1287. * ocfs2_userspace_stack().
  1288. */
  1289. if (memcmp(mopt->cluster_stack,
  1290. OCFS2_CLASSIC_CLUSTER_STACK,
  1291. OCFS2_STACK_LABEL_LEN))
  1292. user_stack = 1;
  1293. break;
  1294. case Opt_inode64:
  1295. mopt->mount_opt |= OCFS2_MOUNT_INODE64;
  1296. break;
  1297. case Opt_usrquota:
  1298. mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA;
  1299. break;
  1300. case Opt_grpquota:
  1301. mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA;
  1302. break;
  1303. case Opt_coherency_buffered:
  1304. mopt->mount_opt |= OCFS2_MOUNT_COHERENCY_BUFFERED;
  1305. break;
  1306. case Opt_coherency_full:
  1307. mopt->mount_opt &= ~OCFS2_MOUNT_COHERENCY_BUFFERED;
  1308. break;
  1309. case Opt_acl:
  1310. mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
  1311. mopt->mount_opt &= ~OCFS2_MOUNT_NO_POSIX_ACL;
  1312. break;
  1313. case Opt_noacl:
  1314. mopt->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
  1315. mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
  1316. break;
  1317. case Opt_resv_level:
  1318. if (is_remount)
  1319. break;
  1320. if (match_int(&args[0], &option)) {
  1321. status = 0;
  1322. goto bail;
  1323. }
  1324. if (option >= OCFS2_MIN_RESV_LEVEL &&
  1325. option < OCFS2_MAX_RESV_LEVEL)
  1326. mopt->resv_level = option;
  1327. break;
  1328. case Opt_dir_resv_level:
  1329. if (is_remount)
  1330. break;
  1331. if (match_int(&args[0], &option)) {
  1332. status = 0;
  1333. goto bail;
  1334. }
  1335. if (option >= OCFS2_MIN_RESV_LEVEL &&
  1336. option < OCFS2_MAX_RESV_LEVEL)
  1337. mopt->dir_resv_level = option;
  1338. break;
  1339. case Opt_journal_async_commit:
  1340. mopt->mount_opt |= OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT;
  1341. break;
  1342. default:
  1343. mlog(ML_ERROR,
  1344. "Unrecognized mount option \"%s\" "
  1345. "or missing value\n", p);
  1346. status = 0;
  1347. goto bail;
  1348. }
  1349. }
  1350. if (user_stack == 0) {
  1351. /* Ensure only one heartbeat mode */
  1352. tmp = mopt->mount_opt & (OCFS2_MOUNT_HB_LOCAL |
  1353. OCFS2_MOUNT_HB_GLOBAL |
  1354. OCFS2_MOUNT_HB_NONE);
  1355. if (hweight32(tmp) != 1) {
  1356. mlog(ML_ERROR, "Invalid heartbeat mount options\n");
  1357. status = 0;
  1358. goto bail;
  1359. }
  1360. }
  1361. status = 1;
  1362. bail:
  1363. return status;
  1364. }
  1365. static int ocfs2_show_options(struct seq_file *s, struct dentry *root)
  1366. {
  1367. struct ocfs2_super *osb = OCFS2_SB(root->d_sb);
  1368. unsigned long opts = osb->s_mount_opt;
  1369. unsigned int local_alloc_megs;
  1370. if (opts & (OCFS2_MOUNT_HB_LOCAL | OCFS2_MOUNT_HB_GLOBAL)) {
  1371. seq_printf(s, ",_netdev");
  1372. if (opts & OCFS2_MOUNT_HB_LOCAL)
  1373. seq_printf(s, ",%s", OCFS2_HB_LOCAL);
  1374. else
  1375. seq_printf(s, ",%s", OCFS2_HB_GLOBAL);
  1376. } else
  1377. seq_printf(s, ",%s", OCFS2_HB_NONE);
  1378. if (opts & OCFS2_MOUNT_NOINTR)
  1379. seq_printf(s, ",nointr");
  1380. if (opts & OCFS2_MOUNT_DATA_WRITEBACK)
  1381. seq_printf(s, ",data=writeback");
  1382. else
  1383. seq_printf(s, ",data=ordered");
  1384. if (opts & OCFS2_MOUNT_BARRIER)
  1385. seq_printf(s, ",barrier=1");
  1386. if (opts & OCFS2_MOUNT_ERRORS_PANIC)
  1387. seq_printf(s, ",errors=panic");
  1388. else if (opts & OCFS2_MOUNT_ERRORS_CONT)
  1389. seq_printf(s, ",errors=continue");
  1390. else
  1391. seq_printf(s, ",errors=remount-ro");
  1392. if (osb->preferred_slot != OCFS2_INVALID_SLOT)
  1393. seq_printf(s, ",preferred_slot=%d", osb->preferred_slot);
  1394. seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum);
  1395. if (osb->osb_commit_interval)
  1396. seq_printf(s, ",commit=%u",
  1397. (unsigned) (osb->osb_commit_interval / HZ));
  1398. local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits);
  1399. if (local_alloc_megs != ocfs2_la_default_mb(osb))
  1400. seq_printf(s, ",localalloc=%d", local_alloc_megs);
  1401. if (opts & OCFS2_MOUNT_LOCALFLOCKS)
  1402. seq_printf(s, ",localflocks,");
  1403. if (osb->osb_cluster_stack[0])
  1404. seq_show_option_n(s, "cluster_stack", osb->osb_cluster_stack,
  1405. OCFS2_STACK_LABEL_LEN);
  1406. if (opts & OCFS2_MOUNT_USRQUOTA)
  1407. seq_printf(s, ",usrquota");
  1408. if (opts & OCFS2_MOUNT_GRPQUOTA)
  1409. seq_printf(s, ",grpquota");
  1410. if (opts & OCFS2_MOUNT_COHERENCY_BUFFERED)
  1411. seq_printf(s, ",coherency=buffered");
  1412. else
  1413. seq_printf(s, ",coherency=full");
  1414. if (opts & OCFS2_MOUNT_NOUSERXATTR)
  1415. seq_printf(s, ",nouser_xattr");
  1416. else
  1417. seq_printf(s, ",user_xattr");
  1418. if (opts & OCFS2_MOUNT_INODE64)
  1419. seq_printf(s, ",inode64");
  1420. if (opts & OCFS2_MOUNT_POSIX_ACL)
  1421. seq_printf(s, ",acl");
  1422. else
  1423. seq_printf(s, ",noacl");
  1424. if (osb->osb_resv_level != OCFS2_DEFAULT_RESV_LEVEL)
  1425. seq_printf(s, ",resv_level=%d", osb->osb_resv_level);
  1426. if (osb->osb_dir_resv_level != osb->osb_resv_level)
  1427. seq_printf(s, ",dir_resv_level=%d", osb->osb_resv_level);
  1428. if (opts & OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT)
  1429. seq_printf(s, ",journal_async_commit");
  1430. return 0;
  1431. }
  1432. static int __init ocfs2_init(void)
  1433. {
  1434. int status;
  1435. status = init_ocfs2_uptodate_cache();
  1436. if (status < 0)
  1437. goto out1;
  1438. status = ocfs2_initialize_mem_caches();
  1439. if (status < 0)
  1440. goto out2;
  1441. ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
  1442. if (!ocfs2_debugfs_root) {
  1443. status = -ENOMEM;
  1444. mlog(ML_ERROR, "Unable to create ocfs2 debugfs root.\n");
  1445. goto out3;
  1446. }
  1447. ocfs2_set_locking_protocol();
  1448. status = register_quota_format(&ocfs2_quota_format);
  1449. if (status < 0)
  1450. goto out3;
  1451. status = register_filesystem(&ocfs2_fs_type);
  1452. if (!status)
  1453. return 0;
  1454. unregister_quota_format(&ocfs2_quota_format);
  1455. out3:
  1456. debugfs_remove(ocfs2_debugfs_root);
  1457. ocfs2_free_mem_caches();
  1458. out2:
  1459. exit_ocfs2_uptodate_cache();
  1460. out1:
  1461. mlog_errno(status);
  1462. return status;
  1463. }
  1464. static void __exit ocfs2_exit(void)
  1465. {
  1466. unregister_quota_format(&ocfs2_quota_format);
  1467. debugfs_remove(ocfs2_debugfs_root);
  1468. ocfs2_free_mem_caches();
  1469. unregister_filesystem(&ocfs2_fs_type);
  1470. exit_ocfs2_uptodate_cache();
  1471. }
  1472. static void ocfs2_put_super(struct super_block *sb)
  1473. {
  1474. trace_ocfs2_put_super(sb);
  1475. ocfs2_sync_blockdev(sb);
  1476. ocfs2_dismount_volume(sb, 0);
  1477. }
  1478. static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
  1479. {
  1480. struct ocfs2_super *osb;
  1481. u32 numbits, freebits;
  1482. int status;
  1483. struct ocfs2_dinode *bm_lock;
  1484. struct buffer_head *bh = NULL;
  1485. struct inode *inode = NULL;
  1486. trace_ocfs2_statfs(dentry->d_sb, buf);
  1487. osb = OCFS2_SB(dentry->d_sb);
  1488. inode = ocfs2_get_system_file_inode(osb,
  1489. GLOBAL_BITMAP_SYSTEM_INODE,
  1490. OCFS2_INVALID_SLOT);
  1491. if (!inode) {
  1492. mlog(ML_ERROR, "failed to get bitmap inode\n");
  1493. status = -EIO;
  1494. goto bail;
  1495. }
  1496. status = ocfs2_inode_lock(inode, &bh, 0);
  1497. if (status < 0) {
  1498. mlog_errno(status);
  1499. goto bail;
  1500. }
  1501. bm_lock = (struct ocfs2_dinode *) bh->b_data;
  1502. numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total);
  1503. freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used);
  1504. buf->f_type = OCFS2_SUPER_MAGIC;
  1505. buf->f_bsize = dentry->d_sb->s_blocksize;
  1506. buf->f_namelen = OCFS2_MAX_FILENAME_LEN;
  1507. buf->f_blocks = ((sector_t) numbits) *
  1508. (osb->s_clustersize >> osb->sb->s_blocksize_bits);
  1509. buf->f_bfree = ((sector_t) freebits) *
  1510. (osb->s_clustersize >> osb->sb->s_blocksize_bits);
  1511. buf->f_bavail = buf->f_bfree;
  1512. buf->f_files = numbits;
  1513. buf->f_ffree = freebits;
  1514. buf->f_fsid.val[0] = crc32_le(0, osb->uuid_str, OCFS2_VOL_UUID_LEN)
  1515. & 0xFFFFFFFFUL;
  1516. buf->f_fsid.val[1] = crc32_le(0, osb->uuid_str + OCFS2_VOL_UUID_LEN,
  1517. OCFS2_VOL_UUID_LEN) & 0xFFFFFFFFUL;
  1518. brelse(bh);
  1519. ocfs2_inode_unlock(inode, 0);
  1520. status = 0;
  1521. bail:
  1522. iput(inode);
  1523. if (status)
  1524. mlog_errno(status);
  1525. return status;
  1526. }
  1527. static void ocfs2_inode_init_once(void *data)
  1528. {
  1529. struct ocfs2_inode_info *oi = data;
  1530. oi->ip_flags = 0;
  1531. oi->ip_open_count = 0;
  1532. spin_lock_init(&oi->ip_lock);
  1533. ocfs2_extent_map_init(&oi->vfs_inode);
  1534. INIT_LIST_HEAD(&oi->ip_io_markers);
  1535. INIT_LIST_HEAD(&oi->ip_unwritten_list);
  1536. oi->ip_dir_start_lookup = 0;
  1537. init_rwsem(&oi->ip_alloc_sem);
  1538. init_rwsem(&oi->ip_xattr_sem);
  1539. mutex_init(&oi->ip_io_mutex);
  1540. oi->ip_blkno = 0ULL;
  1541. oi->ip_clusters = 0;
  1542. ocfs2_resv_init_once(&oi->ip_la_data_resv);
  1543. ocfs2_lock_res_init_once(&oi->ip_rw_lockres);
  1544. ocfs2_lock_res_init_once(&oi->ip_inode_lockres);
  1545. ocfs2_lock_res_init_once(&oi->ip_open_lockres);
  1546. ocfs2_metadata_cache_init(INODE_CACHE(&oi->vfs_inode),
  1547. &ocfs2_inode_caching_ops);
  1548. inode_init_once(&oi->vfs_inode);
  1549. }
  1550. static int ocfs2_initialize_mem_caches(void)
  1551. {
  1552. ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache",
  1553. sizeof(struct ocfs2_inode_info),
  1554. 0,
  1555. (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
  1556. SLAB_MEM_SPREAD|SLAB_ACCOUNT),
  1557. ocfs2_inode_init_once);
  1558. ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache",
  1559. sizeof(struct ocfs2_dquot),
  1560. 0,
  1561. (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
  1562. SLAB_MEM_SPREAD),
  1563. NULL);
  1564. ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache",
  1565. sizeof(struct ocfs2_quota_chunk),
  1566. 0,
  1567. (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
  1568. NULL);
  1569. if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
  1570. !ocfs2_qf_chunk_cachep) {
  1571. kmem_cache_destroy(ocfs2_inode_cachep);
  1572. kmem_cache_destroy(ocfs2_dquot_cachep);
  1573. kmem_cache_destroy(ocfs2_qf_chunk_cachep);
  1574. return -ENOMEM;
  1575. }
  1576. return 0;
  1577. }
  1578. static void ocfs2_free_mem_caches(void)
  1579. {
  1580. /*
  1581. * Make sure all delayed rcu free inodes are flushed before we
  1582. * destroy cache.
  1583. */
  1584. rcu_barrier();
  1585. kmem_cache_destroy(ocfs2_inode_cachep);
  1586. ocfs2_inode_cachep = NULL;
  1587. kmem_cache_destroy(ocfs2_dquot_cachep);
  1588. ocfs2_dquot_cachep = NULL;
  1589. kmem_cache_destroy(ocfs2_qf_chunk_cachep);
  1590. ocfs2_qf_chunk_cachep = NULL;
  1591. }
  1592. static int ocfs2_get_sector(struct super_block *sb,
  1593. struct buffer_head **bh,
  1594. int block,
  1595. int sect_size)
  1596. {
  1597. if (!sb_set_blocksize(sb, sect_size)) {
  1598. mlog(ML_ERROR, "unable to set blocksize\n");
  1599. return -EIO;
  1600. }
  1601. *bh = sb_getblk(sb, block);
  1602. if (!*bh) {
  1603. mlog_errno(-ENOMEM);
  1604. return -ENOMEM;
  1605. }
  1606. lock_buffer(*bh);
  1607. if (!buffer_dirty(*bh))
  1608. clear_buffer_uptodate(*bh);
  1609. unlock_buffer(*bh);
  1610. ll_rw_block(REQ_OP_READ, 0, 1, bh);
  1611. wait_on_buffer(*bh);
  1612. if (!buffer_uptodate(*bh)) {
  1613. mlog_errno(-EIO);
  1614. brelse(*bh);
  1615. *bh = NULL;
  1616. return -EIO;
  1617. }
  1618. return 0;
  1619. }
  1620. static int ocfs2_mount_volume(struct super_block *sb)
  1621. {
  1622. int status = 0;
  1623. int unlock_super = 0;
  1624. struct ocfs2_super *osb = OCFS2_SB(sb);
  1625. if (ocfs2_is_hard_readonly(osb))
  1626. goto leave;
  1627. status = ocfs2_dlm_init(osb);
  1628. if (status < 0) {
  1629. mlog_errno(status);
  1630. if (status == -EBADR && ocfs2_userspace_stack(osb))
  1631. mlog(ML_ERROR, "couldn't mount because cluster name on"
  1632. " disk does not match the running cluster name.\n");
  1633. goto leave;
  1634. }
  1635. status = ocfs2_super_lock(osb, 1);
  1636. if (status < 0) {
  1637. mlog_errno(status);
  1638. goto leave;
  1639. }
  1640. unlock_super = 1;
  1641. /* This will load up the node map and add ourselves to it. */
  1642. status = ocfs2_find_slot(osb);
  1643. if (status < 0) {
  1644. mlog_errno(status);
  1645. goto leave;
  1646. }
  1647. /* load all node-local system inodes */
  1648. status = ocfs2_init_local_system_inodes(osb);
  1649. if (status < 0) {
  1650. mlog_errno(status);
  1651. goto leave;
  1652. }
  1653. status = ocfs2_check_volume(osb);
  1654. if (status < 0) {
  1655. mlog_errno(status);
  1656. goto leave;
  1657. }
  1658. status = ocfs2_truncate_log_init(osb);
  1659. if (status < 0)
  1660. mlog_errno(status);
  1661. leave:
  1662. if (unlock_super)
  1663. ocfs2_super_unlock(osb, 1);
  1664. return status;
  1665. }
  1666. static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
  1667. {
  1668. int tmp, hangup_needed = 0;
  1669. struct ocfs2_super *osb = NULL;
  1670. char nodestr[12];
  1671. trace_ocfs2_dismount_volume(sb);
  1672. BUG_ON(!sb);
  1673. osb = OCFS2_SB(sb);
  1674. BUG_ON(!osb);
  1675. /* Remove file check sysfs related directores/files,
  1676. * and wait for the pending file check operations */
  1677. ocfs2_filecheck_remove_sysfs(osb);
  1678. kset_unregister(osb->osb_dev_kset);
  1679. debugfs_remove(osb->osb_ctxt);
  1680. /* Orphan scan should be stopped as early as possible */
  1681. ocfs2_orphan_scan_stop(osb);
  1682. ocfs2_disable_quotas(osb);
  1683. /* All dquots should be freed by now */
  1684. WARN_ON(!llist_empty(&osb->dquot_drop_list));
  1685. /* Wait for worker to be done with the work structure in osb */
  1686. cancel_work_sync(&osb->dquot_drop_work);
  1687. ocfs2_shutdown_local_alloc(osb);
  1688. ocfs2_truncate_log_shutdown(osb);
  1689. /* This will disable recovery and flush any recovery work. */
  1690. ocfs2_recovery_exit(osb);
  1691. ocfs2_journal_shutdown(osb);
  1692. ocfs2_sync_blockdev(sb);
  1693. ocfs2_purge_refcount_trees(osb);
  1694. /* No cluster connection means we've failed during mount, so skip
  1695. * all the steps which depended on that to complete. */
  1696. if (osb->cconn) {
  1697. tmp = ocfs2_super_lock(osb, 1);
  1698. if (tmp < 0) {
  1699. mlog_errno(tmp);
  1700. return;
  1701. }
  1702. }
  1703. if (osb->slot_num != OCFS2_INVALID_SLOT)
  1704. ocfs2_put_slot(osb);
  1705. if (osb->cconn)
  1706. ocfs2_super_unlock(osb, 1);
  1707. ocfs2_release_system_inodes(osb);
  1708. /*
  1709. * If we're dismounting due to mount error, mount.ocfs2 will clean
  1710. * up heartbeat. If we're a local mount, there is no heartbeat.
  1711. * If we failed before we got a uuid_str yet, we can't stop
  1712. * heartbeat. Otherwise, do it.
  1713. */
  1714. if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str &&
  1715. !ocfs2_is_hard_readonly(osb))
  1716. hangup_needed = 1;
  1717. if (osb->cconn)
  1718. ocfs2_dlm_shutdown(osb, hangup_needed);
  1719. ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats);
  1720. debugfs_remove(osb->osb_debug_root);
  1721. if (hangup_needed)
  1722. ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));
  1723. atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
  1724. if (ocfs2_mount_local(osb))
  1725. snprintf(nodestr, sizeof(nodestr), "local");
  1726. else
  1727. snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
  1728. printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
  1729. osb->dev_str, nodestr);
  1730. ocfs2_delete_osb(osb);
  1731. kfree(osb);
  1732. sb->s_dev = 0;
  1733. sb->s_fs_info = NULL;
  1734. }
  1735. static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid,
  1736. unsigned uuid_bytes)
  1737. {
  1738. int i, ret;
  1739. char *ptr;
  1740. BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN);
  1741. osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL);
  1742. if (osb->uuid_str == NULL)
  1743. return -ENOMEM;
  1744. for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) {
  1745. /* print with null */
  1746. ret = snprintf(ptr, 3, "%02X", uuid[i]);
  1747. if (ret != 2) /* drop super cleans up */
  1748. return -EINVAL;
  1749. /* then only advance past the last char */
  1750. ptr += 2;
  1751. }
  1752. return 0;
  1753. }
  1754. /* Make sure entire volume is addressable by our journal. Requires
  1755. osb_clusters_at_boot to be valid and for the journal to have been
  1756. initialized by ocfs2_journal_init(). */
  1757. static int ocfs2_journal_addressable(struct ocfs2_super *osb)
  1758. {
  1759. int status = 0;
  1760. u64 max_block =
  1761. ocfs2_clusters_to_blocks(osb->sb,
  1762. osb->osb_clusters_at_boot) - 1;
  1763. /* 32-bit block number is always OK. */
  1764. if (max_block <= (u32)~0ULL)
  1765. goto out;
  1766. /* Volume is "huge", so see if our journal is new enough to
  1767. support it. */
  1768. if (!(OCFS2_HAS_COMPAT_FEATURE(osb->sb,
  1769. OCFS2_FEATURE_COMPAT_JBD2_SB) &&
  1770. jbd2_journal_check_used_features(osb->journal->j_journal, 0, 0,
  1771. JBD2_FEATURE_INCOMPAT_64BIT))) {
  1772. mlog(ML_ERROR, "The journal cannot address the entire volume. "
  1773. "Enable the 'block64' journal option with tunefs.ocfs2");
  1774. status = -EFBIG;
  1775. goto out;
  1776. }
  1777. out:
  1778. return status;
  1779. }
  1780. static int ocfs2_initialize_super(struct super_block *sb,
  1781. struct buffer_head *bh,
  1782. int sector_size,
  1783. struct ocfs2_blockcheck_stats *stats)
  1784. {
  1785. int status;
  1786. int i, cbits, bbits;
  1787. struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
  1788. struct inode *inode = NULL;
  1789. struct ocfs2_journal *journal;
  1790. struct ocfs2_super *osb;
  1791. u64 total_blocks;
  1792. osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL);
  1793. if (!osb) {
  1794. status = -ENOMEM;
  1795. mlog_errno(status);
  1796. goto bail;
  1797. }
  1798. sb->s_fs_info = osb;
  1799. sb->s_op = &ocfs2_sops;
  1800. sb->s_d_op = &ocfs2_dentry_ops;
  1801. sb->s_export_op = &ocfs2_export_ops;
  1802. sb->s_qcop = &dquot_quotactl_sysfile_ops;
  1803. sb->dq_op = &ocfs2_quota_operations;
  1804. sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP;
  1805. sb->s_xattr = ocfs2_xattr_handlers;
  1806. sb->s_time_gran = 1;
  1807. sb->s_flags |= SB_NOATIME;
  1808. /* this is needed to support O_LARGEFILE */
  1809. cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
  1810. bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
  1811. sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
  1812. memcpy(&sb->s_uuid, di->id2.i_super.s_uuid,
  1813. sizeof(di->id2.i_super.s_uuid));
  1814. osb->osb_dx_mask = (1 << (cbits - bbits)) - 1;
  1815. for (i = 0; i < 3; i++)
  1816. osb->osb_dx_seed[i] = le32_to_cpu(di->id2.i_super.s_dx_seed[i]);
  1817. osb->osb_dx_seed[3] = le32_to_cpu(di->id2.i_super.s_uuid_hash);
  1818. osb->sb = sb;
  1819. osb->s_sectsize_bits = blksize_bits(sector_size);
  1820. BUG_ON(!osb->s_sectsize_bits);
  1821. spin_lock_init(&osb->dc_task_lock);
  1822. init_waitqueue_head(&osb->dc_event);
  1823. osb->dc_work_sequence = 0;
  1824. osb->dc_wake_sequence = 0;
  1825. INIT_LIST_HEAD(&osb->blocked_lock_list);
  1826. osb->blocked_lock_count = 0;
  1827. spin_lock_init(&osb->osb_lock);
  1828. spin_lock_init(&osb->osb_xattr_lock);
  1829. ocfs2_init_steal_slots(osb);
  1830. mutex_init(&osb->system_file_mutex);
  1831. atomic_set(&osb->alloc_stats.moves, 0);
  1832. atomic_set(&osb->alloc_stats.local_data, 0);
  1833. atomic_set(&osb->alloc_stats.bitmap_data, 0);
  1834. atomic_set(&osb->alloc_stats.bg_allocs, 0);
  1835. atomic_set(&osb->alloc_stats.bg_extends, 0);
  1836. /* Copy the blockcheck stats from the superblock probe */
  1837. osb->osb_ecc_stats = *stats;
  1838. ocfs2_init_node_maps(osb);
  1839. snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
  1840. MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
  1841. osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
  1842. if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
  1843. mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
  1844. osb->max_slots);
  1845. status = -EINVAL;
  1846. goto bail;
  1847. }
  1848. ocfs2_orphan_scan_init(osb);
  1849. status = ocfs2_recovery_init(osb);
  1850. if (status) {
  1851. mlog(ML_ERROR, "Unable to initialize recovery state\n");
  1852. mlog_errno(status);
  1853. goto bail;
  1854. }
  1855. init_waitqueue_head(&osb->checkpoint_event);
  1856. osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
  1857. osb->slot_num = OCFS2_INVALID_SLOT;
  1858. osb->s_xattr_inline_size = le16_to_cpu(
  1859. di->id2.i_super.s_xattr_inline_size);
  1860. osb->local_alloc_state = OCFS2_LA_UNUSED;
  1861. osb->local_alloc_bh = NULL;
  1862. INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker);
  1863. init_waitqueue_head(&osb->osb_mount_event);
  1864. status = ocfs2_resmap_init(osb, &osb->osb_la_resmap);
  1865. if (status) {
  1866. mlog_errno(status);
  1867. goto bail;
  1868. }
  1869. osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL);
  1870. if (!osb->vol_label) {
  1871. mlog(ML_ERROR, "unable to alloc vol label\n");
  1872. status = -ENOMEM;
  1873. goto bail;
  1874. }
  1875. osb->slot_recovery_generations =
  1876. kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
  1877. GFP_KERNEL);
  1878. if (!osb->slot_recovery_generations) {
  1879. status = -ENOMEM;
  1880. mlog_errno(status);
  1881. goto bail;
  1882. }
  1883. init_waitqueue_head(&osb->osb_wipe_event);
  1884. osb->osb_orphan_wipes = kcalloc(osb->max_slots,
  1885. sizeof(*osb->osb_orphan_wipes),
  1886. GFP_KERNEL);
  1887. if (!osb->osb_orphan_wipes) {
  1888. status = -ENOMEM;
  1889. mlog_errno(status);
  1890. goto bail;
  1891. }
  1892. osb->osb_rf_lock_tree = RB_ROOT;
  1893. osb->s_feature_compat =
  1894. le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat);
  1895. osb->s_feature_ro_compat =
  1896. le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat);
  1897. osb->s_feature_incompat =
  1898. le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat);
  1899. if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) {
  1900. mlog(ML_ERROR, "couldn't mount because of unsupported "
  1901. "optional features (%x).\n", i);
  1902. status = -EINVAL;
  1903. goto bail;
  1904. }
  1905. if (!sb_rdonly(osb->sb) && (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) {
  1906. mlog(ML_ERROR, "couldn't mount RDWR because of "
  1907. "unsupported optional features (%x).\n", i);
  1908. status = -EINVAL;
  1909. goto bail;
  1910. }
  1911. if (ocfs2_clusterinfo_valid(osb)) {
  1912. osb->osb_stackflags =
  1913. OCFS2_RAW_SB(di)->s_cluster_info.ci_stackflags;
  1914. strlcpy(osb->osb_cluster_stack,
  1915. OCFS2_RAW_SB(di)->s_cluster_info.ci_stack,
  1916. OCFS2_STACK_LABEL_LEN + 1);
  1917. if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) {
  1918. mlog(ML_ERROR,
  1919. "couldn't mount because of an invalid "
  1920. "cluster stack label (%s) \n",
  1921. osb->osb_cluster_stack);
  1922. status = -EINVAL;
  1923. goto bail;
  1924. }
  1925. strlcpy(osb->osb_cluster_name,
  1926. OCFS2_RAW_SB(di)->s_cluster_info.ci_cluster,
  1927. OCFS2_CLUSTER_NAME_LEN + 1);
  1928. } else {
  1929. /* The empty string is identical with classic tools that
  1930. * don't know about s_cluster_info. */
  1931. osb->osb_cluster_stack[0] = '\0';
  1932. }
  1933. get_random_bytes(&osb->s_next_generation, sizeof(u32));
  1934. /* FIXME
  1935. * This should be done in ocfs2_journal_init(), but unknown
  1936. * ordering issues will cause the filesystem to crash.
  1937. * If anyone wants to figure out what part of the code
  1938. * refers to osb->journal before ocfs2_journal_init() is run,
  1939. * be my guest.
  1940. */
  1941. /* initialize our journal structure */
  1942. journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
  1943. if (!journal) {
  1944. mlog(ML_ERROR, "unable to alloc journal\n");
  1945. status = -ENOMEM;
  1946. goto bail;
  1947. }
  1948. osb->journal = journal;
  1949. journal->j_osb = osb;
  1950. atomic_set(&journal->j_num_trans, 0);
  1951. init_rwsem(&journal->j_trans_barrier);
  1952. init_waitqueue_head(&journal->j_checkpointed);
  1953. spin_lock_init(&journal->j_lock);
  1954. journal->j_trans_id = (unsigned long) 1;
  1955. INIT_LIST_HEAD(&journal->j_la_cleanups);
  1956. INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
  1957. journal->j_state = OCFS2_JOURNAL_FREE;
  1958. INIT_WORK(&osb->dquot_drop_work, ocfs2_drop_dquot_refs);
  1959. init_llist_head(&osb->dquot_drop_list);
  1960. /* get some pseudo constants for clustersize bits */
  1961. osb->s_clustersize_bits =
  1962. le32_to_cpu(di->id2.i_super.s_clustersize_bits);
  1963. osb->s_clustersize = 1 << osb->s_clustersize_bits;
  1964. if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE ||
  1965. osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) {
  1966. mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n",
  1967. osb->s_clustersize);
  1968. status = -EINVAL;
  1969. goto bail;
  1970. }
  1971. total_blocks = ocfs2_clusters_to_blocks(osb->sb,
  1972. le32_to_cpu(di->i_clusters));
  1973. status = generic_check_addressable(osb->sb->s_blocksize_bits,
  1974. total_blocks);
  1975. if (status) {
  1976. mlog(ML_ERROR, "Volume too large "
  1977. "to mount safely on this system");
  1978. status = -EFBIG;
  1979. goto bail;
  1980. }
  1981. if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid,
  1982. sizeof(di->id2.i_super.s_uuid))) {
  1983. mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n");
  1984. status = -ENOMEM;
  1985. goto bail;
  1986. }
  1987. strlcpy(osb->vol_label, di->id2.i_super.s_label,
  1988. OCFS2_MAX_VOL_LABEL_LEN);
  1989. osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno);
  1990. osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno);
  1991. osb->first_cluster_group_blkno =
  1992. le64_to_cpu(di->id2.i_super.s_first_cluster_group);
  1993. osb->fs_generation = le32_to_cpu(di->i_fs_generation);
  1994. osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
  1995. trace_ocfs2_initialize_super(osb->vol_label, osb->uuid_str,
  1996. (unsigned long long)osb->root_blkno,
  1997. (unsigned long long)osb->system_dir_blkno,
  1998. osb->s_clustersize_bits);
  1999. osb->osb_dlm_debug = ocfs2_new_dlm_debug();
  2000. if (!osb->osb_dlm_debug) {
  2001. status = -ENOMEM;
  2002. mlog_errno(status);
  2003. goto bail;
  2004. }
  2005. atomic_set(&osb->vol_state, VOLUME_INIT);
  2006. /* load root, system_dir, and all global system inodes */
  2007. status = ocfs2_init_global_system_inodes(osb);
  2008. if (status < 0) {
  2009. mlog_errno(status);
  2010. goto bail;
  2011. }
  2012. /*
  2013. * global bitmap
  2014. */
  2015. inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE,
  2016. OCFS2_INVALID_SLOT);
  2017. if (!inode) {
  2018. status = -EINVAL;
  2019. mlog_errno(status);
  2020. goto bail;
  2021. }
  2022. osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno;
  2023. osb->osb_clusters_at_boot = OCFS2_I(inode)->ip_clusters;
  2024. iput(inode);
  2025. osb->bitmap_cpg = ocfs2_group_bitmap_size(sb, 0,
  2026. osb->s_feature_incompat) * 8;
  2027. status = ocfs2_init_slot_info(osb);
  2028. if (status < 0) {
  2029. mlog_errno(status);
  2030. goto bail;
  2031. }
  2032. cleancache_init_shared_fs(sb);
  2033. osb->ocfs2_wq = alloc_ordered_workqueue("ocfs2_wq", WQ_MEM_RECLAIM);
  2034. if (!osb->ocfs2_wq) {
  2035. status = -ENOMEM;
  2036. mlog_errno(status);
  2037. }
  2038. bail:
  2039. return status;
  2040. }
  2041. /*
  2042. * will return: -EAGAIN if it is ok to keep searching for superblocks
  2043. * -EINVAL if there is a bad superblock
  2044. * 0 on success
  2045. */
  2046. static int ocfs2_verify_volume(struct ocfs2_dinode *di,
  2047. struct buffer_head *bh,
  2048. u32 blksz,
  2049. struct ocfs2_blockcheck_stats *stats)
  2050. {
  2051. int status = -EAGAIN;
  2052. if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
  2053. strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
  2054. /* We have to do a raw check of the feature here */
  2055. if (le32_to_cpu(di->id2.i_super.s_feature_incompat) &
  2056. OCFS2_FEATURE_INCOMPAT_META_ECC) {
  2057. status = ocfs2_block_check_validate(bh->b_data,
  2058. bh->b_size,
  2059. &di->i_check,
  2060. stats);
  2061. if (status)
  2062. goto out;
  2063. }
  2064. status = -EINVAL;
  2065. if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) {
  2066. mlog(ML_ERROR, "found superblock with incorrect block "
  2067. "size: found %u, should be %u\n",
  2068. 1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits),
  2069. blksz);
  2070. } else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) !=
  2071. OCFS2_MAJOR_REV_LEVEL ||
  2072. le16_to_cpu(di->id2.i_super.s_minor_rev_level) !=
  2073. OCFS2_MINOR_REV_LEVEL) {
  2074. mlog(ML_ERROR, "found superblock with bad version: "
  2075. "found %u.%u, should be %u.%u\n",
  2076. le16_to_cpu(di->id2.i_super.s_major_rev_level),
  2077. le16_to_cpu(di->id2.i_super.s_minor_rev_level),
  2078. OCFS2_MAJOR_REV_LEVEL,
  2079. OCFS2_MINOR_REV_LEVEL);
  2080. } else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) {
  2081. mlog(ML_ERROR, "bad block number on superblock: "
  2082. "found %llu, should be %llu\n",
  2083. (unsigned long long)le64_to_cpu(di->i_blkno),
  2084. (unsigned long long)bh->b_blocknr);
  2085. } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 ||
  2086. le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) {
  2087. mlog(ML_ERROR, "bad cluster size found: %u\n",
  2088. 1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits));
  2089. } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) {
  2090. mlog(ML_ERROR, "bad root_blkno: 0\n");
  2091. } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) {
  2092. mlog(ML_ERROR, "bad system_dir_blkno: 0\n");
  2093. } else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) {
  2094. mlog(ML_ERROR,
  2095. "Superblock slots found greater than file system "
  2096. "maximum: found %u, max %u\n",
  2097. le16_to_cpu(di->id2.i_super.s_max_slots),
  2098. OCFS2_MAX_SLOTS);
  2099. } else {
  2100. /* found it! */
  2101. status = 0;
  2102. }
  2103. }
  2104. out:
  2105. if (status && status != -EAGAIN)
  2106. mlog_errno(status);
  2107. return status;
  2108. }
  2109. static int ocfs2_check_volume(struct ocfs2_super *osb)
  2110. {
  2111. int status;
  2112. int dirty;
  2113. int local;
  2114. struct ocfs2_dinode *local_alloc = NULL; /* only used if we
  2115. * recover
  2116. * ourselves. */
  2117. /* Init our journal object. */
  2118. status = ocfs2_journal_init(osb->journal, &dirty);
  2119. if (status < 0) {
  2120. mlog(ML_ERROR, "Could not initialize journal!\n");
  2121. goto finally;
  2122. }
  2123. /* Now that journal has been initialized, check to make sure
  2124. entire volume is addressable. */
  2125. status = ocfs2_journal_addressable(osb);
  2126. if (status)
  2127. goto finally;
  2128. /* If the journal was unmounted cleanly then we don't want to
  2129. * recover anything. Otherwise, journal_load will do that
  2130. * dirty work for us :) */
  2131. if (!dirty) {
  2132. status = ocfs2_journal_wipe(osb->journal, 0);
  2133. if (status < 0) {
  2134. mlog_errno(status);
  2135. goto finally;
  2136. }
  2137. } else {
  2138. printk(KERN_NOTICE "ocfs2: File system on device (%s) was not "
  2139. "unmounted cleanly, recovering it.\n", osb->dev_str);
  2140. }
  2141. local = ocfs2_mount_local(osb);
  2142. /* will play back anything left in the journal. */
  2143. status = ocfs2_journal_load(osb->journal, local, dirty);
  2144. if (status < 0) {
  2145. mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status);
  2146. goto finally;
  2147. }
  2148. if (osb->s_mount_opt & OCFS2_MOUNT_JOURNAL_ASYNC_COMMIT)
  2149. jbd2_journal_set_features(osb->journal->j_journal,
  2150. JBD2_FEATURE_COMPAT_CHECKSUM, 0,
  2151. JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
  2152. else
  2153. jbd2_journal_clear_features(osb->journal->j_journal,
  2154. JBD2_FEATURE_COMPAT_CHECKSUM, 0,
  2155. JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT);
  2156. if (dirty) {
  2157. /* recover my local alloc if we didn't unmount cleanly. */
  2158. status = ocfs2_begin_local_alloc_recovery(osb,
  2159. osb->slot_num,
  2160. &local_alloc);
  2161. if (status < 0) {
  2162. mlog_errno(status);
  2163. goto finally;
  2164. }
  2165. /* we complete the recovery process after we've marked
  2166. * ourselves as mounted. */
  2167. }
  2168. status = ocfs2_load_local_alloc(osb);
  2169. if (status < 0) {
  2170. mlog_errno(status);
  2171. goto finally;
  2172. }
  2173. if (dirty) {
  2174. /* Recovery will be completed after we've mounted the
  2175. * rest of the volume. */
  2176. osb->local_alloc_copy = local_alloc;
  2177. local_alloc = NULL;
  2178. }
  2179. /* go through each journal, trylock it and if you get the
  2180. * lock, and it's marked as dirty, set the bit in the recover
  2181. * map and launch a recovery thread for it. */
  2182. status = ocfs2_mark_dead_nodes(osb);
  2183. if (status < 0) {
  2184. mlog_errno(status);
  2185. goto finally;
  2186. }
  2187. status = ocfs2_compute_replay_slots(osb);
  2188. if (status < 0)
  2189. mlog_errno(status);
  2190. finally:
  2191. kfree(local_alloc);
  2192. if (status)
  2193. mlog_errno(status);
  2194. return status;
  2195. }
  2196. /*
  2197. * The routine gets called from dismount or close whenever a dismount on
  2198. * volume is requested and the osb open count becomes 1.
  2199. * It will remove the osb from the global list and also free up all the
  2200. * initialized resources and fileobject.
  2201. */
  2202. static void ocfs2_delete_osb(struct ocfs2_super *osb)
  2203. {
  2204. /* This function assumes that the caller has the main osb resource */
  2205. /* ocfs2_initializer_super have already created this workqueue */
  2206. if (osb->ocfs2_wq)
  2207. destroy_workqueue(osb->ocfs2_wq);
  2208. ocfs2_free_slot_info(osb);
  2209. kfree(osb->osb_orphan_wipes);
  2210. kfree(osb->slot_recovery_generations);
  2211. /* FIXME
  2212. * This belongs in journal shutdown, but because we have to
  2213. * allocate osb->journal at the start of ocfs2_initialize_osb(),
  2214. * we free it here.
  2215. */
  2216. kfree(osb->journal);
  2217. kfree(osb->local_alloc_copy);
  2218. kfree(osb->uuid_str);
  2219. kfree(osb->vol_label);
  2220. ocfs2_put_dlm_debug(osb->osb_dlm_debug);
  2221. memset(osb, 0, sizeof(struct ocfs2_super));
  2222. }
  2223. /* Depending on the mount option passed, perform one of the following:
  2224. * Put OCFS2 into a readonly state (default)
  2225. * Return EIO so that only the process errs
  2226. * Fix the error as if fsck.ocfs2 -y
  2227. * panic
  2228. */
  2229. static int ocfs2_handle_error(struct super_block *sb)
  2230. {
  2231. struct ocfs2_super *osb = OCFS2_SB(sb);
  2232. int rv = 0;
  2233. ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS);
  2234. pr_crit("On-disk corruption discovered. "
  2235. "Please run fsck.ocfs2 once the filesystem is unmounted.\n");
  2236. if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC) {
  2237. panic("OCFS2: (device %s): panic forced after error\n",
  2238. sb->s_id);
  2239. } else if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_CONT) {
  2240. pr_crit("OCFS2: Returning error to the calling process.\n");
  2241. rv = -EIO;
  2242. } else { /* default option */
  2243. rv = -EROFS;
  2244. if (sb_rdonly(sb) && (ocfs2_is_soft_readonly(osb) || ocfs2_is_hard_readonly(osb)))
  2245. return rv;
  2246. pr_crit("OCFS2: File system is now read-only.\n");
  2247. sb->s_flags |= SB_RDONLY;
  2248. ocfs2_set_ro_flag(osb, 0);
  2249. }
  2250. return rv;
  2251. }
  2252. int __ocfs2_error(struct super_block *sb, const char *function,
  2253. const char *fmt, ...)
  2254. {
  2255. struct va_format vaf;
  2256. va_list args;
  2257. va_start(args, fmt);
  2258. vaf.fmt = fmt;
  2259. vaf.va = &args;
  2260. /* Not using mlog here because we want to show the actual
  2261. * function the error came from. */
  2262. printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %pV",
  2263. sb->s_id, function, &vaf);
  2264. va_end(args);
  2265. return ocfs2_handle_error(sb);
  2266. }
  2267. /* Handle critical errors. This is intentionally more drastic than
  2268. * ocfs2_handle_error, so we only use for things like journal errors,
  2269. * etc. */
  2270. void __ocfs2_abort(struct super_block *sb, const char *function,
  2271. const char *fmt, ...)
  2272. {
  2273. struct va_format vaf;
  2274. va_list args;
  2275. va_start(args, fmt);
  2276. vaf.fmt = fmt;
  2277. vaf.va = &args;
  2278. printk(KERN_CRIT "OCFS2: abort (device %s): %s: %pV",
  2279. sb->s_id, function, &vaf);
  2280. va_end(args);
  2281. /* We don't have the cluster support yet to go straight to
  2282. * hard readonly in here. Until then, we want to keep
  2283. * ocfs2_abort() so that we can at least mark critical
  2284. * errors.
  2285. *
  2286. * TODO: This should abort the journal and alert other nodes
  2287. * that our slot needs recovery. */
  2288. /* Force a panic(). This stinks, but it's better than letting
  2289. * things continue without having a proper hard readonly
  2290. * here. */
  2291. if (!ocfs2_mount_local(OCFS2_SB(sb)))
  2292. OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
  2293. ocfs2_handle_error(sb);
  2294. }
  2295. /*
  2296. * Void signal blockers, because in-kernel sigprocmask() only fails
  2297. * when SIG_* is wrong.
  2298. */
  2299. void ocfs2_block_signals(sigset_t *oldset)
  2300. {
  2301. int rc;
  2302. sigset_t blocked;
  2303. sigfillset(&blocked);
  2304. rc = sigprocmask(SIG_BLOCK, &blocked, oldset);
  2305. BUG_ON(rc);
  2306. }
  2307. void ocfs2_unblock_signals(sigset_t *oldset)
  2308. {
  2309. int rc = sigprocmask(SIG_SETMASK, oldset, NULL);
  2310. BUG_ON(rc);
  2311. }
  2312. module_init(ocfs2_init);
  2313. module_exit(ocfs2_exit);