super.c 69 KB

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