super.c 64 KB

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