super.c 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501
  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. }
  623. out:
  624. unlock_kernel();
  625. return ret;
  626. }
  627. static int ocfs2_sb_probe(struct super_block *sb,
  628. struct buffer_head **bh,
  629. int *sector_size,
  630. struct ocfs2_blockcheck_stats *stats)
  631. {
  632. int status, tmpstat;
  633. struct ocfs1_vol_disk_hdr *hdr;
  634. struct ocfs2_dinode *di;
  635. int blksize;
  636. *bh = NULL;
  637. /* may be > 512 */
  638. *sector_size = bdev_logical_block_size(sb->s_bdev);
  639. if (*sector_size > OCFS2_MAX_BLOCKSIZE) {
  640. mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n",
  641. *sector_size, OCFS2_MAX_BLOCKSIZE);
  642. status = -EINVAL;
  643. goto bail;
  644. }
  645. /* Can this really happen? */
  646. if (*sector_size < OCFS2_MIN_BLOCKSIZE)
  647. *sector_size = OCFS2_MIN_BLOCKSIZE;
  648. /* check block zero for old format */
  649. status = ocfs2_get_sector(sb, bh, 0, *sector_size);
  650. if (status < 0) {
  651. mlog_errno(status);
  652. goto bail;
  653. }
  654. hdr = (struct ocfs1_vol_disk_hdr *) (*bh)->b_data;
  655. if (hdr->major_version == OCFS1_MAJOR_VERSION) {
  656. mlog(ML_ERROR, "incompatible version: %u.%u\n",
  657. hdr->major_version, hdr->minor_version);
  658. status = -EINVAL;
  659. }
  660. if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE,
  661. strlen(OCFS1_VOLUME_SIGNATURE)) == 0) {
  662. mlog(ML_ERROR, "incompatible volume signature: %8s\n",
  663. hdr->signature);
  664. status = -EINVAL;
  665. }
  666. brelse(*bh);
  667. *bh = NULL;
  668. if (status < 0) {
  669. mlog(ML_ERROR, "This is an ocfs v1 filesystem which must be "
  670. "upgraded before mounting with ocfs v2\n");
  671. goto bail;
  672. }
  673. /*
  674. * Now check at magic offset for 512, 1024, 2048, 4096
  675. * blocksizes. 4096 is the maximum blocksize because it is
  676. * the minimum clustersize.
  677. */
  678. status = -EINVAL;
  679. for (blksize = *sector_size;
  680. blksize <= OCFS2_MAX_BLOCKSIZE;
  681. blksize <<= 1) {
  682. tmpstat = ocfs2_get_sector(sb, bh,
  683. OCFS2_SUPER_BLOCK_BLKNO,
  684. blksize);
  685. if (tmpstat < 0) {
  686. status = tmpstat;
  687. mlog_errno(status);
  688. break;
  689. }
  690. di = (struct ocfs2_dinode *) (*bh)->b_data;
  691. memset(stats, 0, sizeof(struct ocfs2_blockcheck_stats));
  692. spin_lock_init(&stats->b_lock);
  693. tmpstat = ocfs2_verify_volume(di, *bh, blksize, stats);
  694. if (tmpstat < 0) {
  695. brelse(*bh);
  696. *bh = NULL;
  697. }
  698. if (tmpstat != -EAGAIN) {
  699. status = tmpstat;
  700. break;
  701. }
  702. }
  703. bail:
  704. return status;
  705. }
  706. static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
  707. {
  708. if (ocfs2_mount_local(osb)) {
  709. if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
  710. mlog(ML_ERROR, "Cannot heartbeat on a locally "
  711. "mounted device.\n");
  712. return -EINVAL;
  713. }
  714. }
  715. if (ocfs2_userspace_stack(osb)) {
  716. if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
  717. mlog(ML_ERROR, "Userspace stack expected, but "
  718. "o2cb heartbeat arguments passed to mount\n");
  719. return -EINVAL;
  720. }
  721. }
  722. if (!(osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
  723. if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) &&
  724. !ocfs2_userspace_stack(osb)) {
  725. mlog(ML_ERROR, "Heartbeat has to be started to mount "
  726. "a read-write clustered device.\n");
  727. return -EINVAL;
  728. }
  729. }
  730. return 0;
  731. }
  732. /*
  733. * If we're using a userspace stack, mount should have passed
  734. * a name that matches the disk. If not, mount should not
  735. * have passed a stack.
  736. */
  737. static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb,
  738. struct mount_options *mopt)
  739. {
  740. if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) {
  741. mlog(ML_ERROR,
  742. "cluster stack passed to mount, but this filesystem "
  743. "does not support it\n");
  744. return -EINVAL;
  745. }
  746. if (ocfs2_userspace_stack(osb) &&
  747. strncmp(osb->osb_cluster_stack, mopt->cluster_stack,
  748. OCFS2_STACK_LABEL_LEN)) {
  749. mlog(ML_ERROR,
  750. "cluster stack passed to mount (\"%s\") does not "
  751. "match the filesystem (\"%s\")\n",
  752. mopt->cluster_stack,
  753. osb->osb_cluster_stack);
  754. return -EINVAL;
  755. }
  756. return 0;
  757. }
  758. static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend)
  759. {
  760. int type;
  761. struct super_block *sb = osb->sb;
  762. unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
  763. OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
  764. int status = 0;
  765. for (type = 0; type < MAXQUOTAS; type++) {
  766. if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
  767. continue;
  768. if (unsuspend)
  769. status = vfs_quota_enable(
  770. sb_dqopt(sb)->files[type],
  771. type, QFMT_OCFS2,
  772. DQUOT_SUSPENDED);
  773. else
  774. status = vfs_quota_disable(sb, type,
  775. DQUOT_SUSPENDED);
  776. if (status < 0)
  777. break;
  778. }
  779. if (status < 0)
  780. mlog(ML_ERROR, "Failed to suspend/unsuspend quotas on "
  781. "remount (error = %d).\n", status);
  782. return status;
  783. }
  784. static int ocfs2_enable_quotas(struct ocfs2_super *osb)
  785. {
  786. struct inode *inode[MAXQUOTAS] = { NULL, NULL };
  787. struct super_block *sb = osb->sb;
  788. unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
  789. OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
  790. unsigned int ino[MAXQUOTAS] = { LOCAL_USER_QUOTA_SYSTEM_INODE,
  791. LOCAL_GROUP_QUOTA_SYSTEM_INODE };
  792. int status;
  793. int type;
  794. sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NEGATIVE_USAGE;
  795. for (type = 0; type < MAXQUOTAS; type++) {
  796. if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
  797. continue;
  798. inode[type] = ocfs2_get_system_file_inode(osb, ino[type],
  799. osb->slot_num);
  800. if (!inode[type]) {
  801. status = -ENOENT;
  802. goto out_quota_off;
  803. }
  804. status = vfs_quota_enable(inode[type], type, QFMT_OCFS2,
  805. DQUOT_USAGE_ENABLED);
  806. if (status < 0)
  807. goto out_quota_off;
  808. }
  809. for (type = 0; type < MAXQUOTAS; type++)
  810. iput(inode[type]);
  811. return 0;
  812. out_quota_off:
  813. ocfs2_disable_quotas(osb);
  814. for (type = 0; type < MAXQUOTAS; type++)
  815. iput(inode[type]);
  816. mlog_errno(status);
  817. return status;
  818. }
  819. static void ocfs2_disable_quotas(struct ocfs2_super *osb)
  820. {
  821. int type;
  822. struct inode *inode;
  823. struct super_block *sb = osb->sb;
  824. /* We mostly ignore errors in this function because there's not much
  825. * we can do when we see them */
  826. for (type = 0; type < MAXQUOTAS; type++) {
  827. if (!sb_has_quota_loaded(sb, type))
  828. continue;
  829. inode = igrab(sb->s_dquot.files[type]);
  830. /* Turn off quotas. This will remove all dquot structures from
  831. * memory and so they will be automatically synced to global
  832. * quota files */
  833. vfs_quota_disable(sb, type, DQUOT_USAGE_ENABLED |
  834. DQUOT_LIMITS_ENABLED);
  835. if (!inode)
  836. continue;
  837. iput(inode);
  838. }
  839. }
  840. /* Handle quota on quotactl */
  841. static int ocfs2_quota_on(struct super_block *sb, int type, int format_id,
  842. char *path, int remount)
  843. {
  844. unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
  845. OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
  846. if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
  847. return -EINVAL;
  848. if (remount)
  849. return 0; /* Just ignore it has been handled in
  850. * ocfs2_remount() */
  851. return vfs_quota_enable(sb_dqopt(sb)->files[type], type,
  852. format_id, DQUOT_LIMITS_ENABLED);
  853. }
  854. /* Handle quota off quotactl */
  855. static int ocfs2_quota_off(struct super_block *sb, int type, int remount)
  856. {
  857. if (remount)
  858. return 0; /* Ignore now and handle later in
  859. * ocfs2_remount() */
  860. return vfs_quota_disable(sb, type, DQUOT_LIMITS_ENABLED);
  861. }
  862. static const struct quotactl_ops ocfs2_quotactl_ops = {
  863. .quota_on = ocfs2_quota_on,
  864. .quota_off = ocfs2_quota_off,
  865. .quota_sync = vfs_quota_sync,
  866. .get_info = vfs_get_dqinfo,
  867. .set_info = vfs_set_dqinfo,
  868. .get_dqblk = vfs_get_dqblk,
  869. .set_dqblk = vfs_set_dqblk,
  870. };
  871. static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
  872. {
  873. struct dentry *root;
  874. int status, sector_size;
  875. struct mount_options parsed_options;
  876. struct inode *inode = NULL;
  877. struct ocfs2_super *osb = NULL;
  878. struct buffer_head *bh = NULL;
  879. char nodestr[8];
  880. struct ocfs2_blockcheck_stats stats;
  881. mlog_entry("%p, %p, %i", sb, data, silent);
  882. if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) {
  883. status = -EINVAL;
  884. goto read_super_error;
  885. }
  886. /* probe for superblock */
  887. status = ocfs2_sb_probe(sb, &bh, &sector_size, &stats);
  888. if (status < 0) {
  889. mlog(ML_ERROR, "superblock probe failed!\n");
  890. goto read_super_error;
  891. }
  892. status = ocfs2_initialize_super(sb, bh, sector_size, &stats);
  893. osb = OCFS2_SB(sb);
  894. if (status < 0) {
  895. mlog_errno(status);
  896. goto read_super_error;
  897. }
  898. brelse(bh);
  899. bh = NULL;
  900. if (!ocfs2_check_set_options(sb, &parsed_options)) {
  901. status = -EINVAL;
  902. goto read_super_error;
  903. }
  904. osb->s_mount_opt = parsed_options.mount_opt;
  905. osb->s_atime_quantum = parsed_options.atime_quantum;
  906. osb->preferred_slot = parsed_options.slot;
  907. osb->osb_commit_interval = parsed_options.commit_interval;
  908. osb->local_alloc_default_bits = ocfs2_megabytes_to_clusters(sb, parsed_options.localalloc_opt);
  909. osb->local_alloc_bits = osb->local_alloc_default_bits;
  910. status = ocfs2_verify_userspace_stack(osb, &parsed_options);
  911. if (status)
  912. goto read_super_error;
  913. sb->s_magic = OCFS2_SUPER_MAGIC;
  914. sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
  915. ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
  916. /* Hard readonly mode only if: bdev_read_only, MS_RDONLY,
  917. * heartbeat=none */
  918. if (bdev_read_only(sb->s_bdev)) {
  919. if (!(sb->s_flags & MS_RDONLY)) {
  920. status = -EACCES;
  921. mlog(ML_ERROR, "Readonly device detected but readonly "
  922. "mount was not specified.\n");
  923. goto read_super_error;
  924. }
  925. /* You should not be able to start a local heartbeat
  926. * on a readonly device. */
  927. if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
  928. status = -EROFS;
  929. mlog(ML_ERROR, "Local heartbeat specified on readonly "
  930. "device.\n");
  931. goto read_super_error;
  932. }
  933. status = ocfs2_check_journals_nolocks(osb);
  934. if (status < 0) {
  935. if (status == -EROFS)
  936. mlog(ML_ERROR, "Recovery required on readonly "
  937. "file system, but write access is "
  938. "unavailable.\n");
  939. else
  940. mlog_errno(status);
  941. goto read_super_error;
  942. }
  943. ocfs2_set_ro_flag(osb, 1);
  944. printk(KERN_NOTICE "Readonly device detected. No cluster "
  945. "services will be utilized for this mount. Recovery "
  946. "will be skipped.\n");
  947. }
  948. if (!ocfs2_is_hard_readonly(osb)) {
  949. if (sb->s_flags & MS_RDONLY)
  950. ocfs2_set_ro_flag(osb, 0);
  951. }
  952. status = ocfs2_verify_heartbeat(osb);
  953. if (status < 0) {
  954. mlog_errno(status);
  955. goto read_super_error;
  956. }
  957. osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
  958. ocfs2_debugfs_root);
  959. if (!osb->osb_debug_root) {
  960. status = -EINVAL;
  961. mlog(ML_ERROR, "Unable to create per-mount debugfs root.\n");
  962. goto read_super_error;
  963. }
  964. osb->osb_ctxt = debugfs_create_file("fs_state", S_IFREG|S_IRUSR,
  965. osb->osb_debug_root,
  966. osb,
  967. &ocfs2_osb_debug_fops);
  968. if (!osb->osb_ctxt) {
  969. status = -EINVAL;
  970. mlog_errno(status);
  971. goto read_super_error;
  972. }
  973. if (ocfs2_meta_ecc(osb)) {
  974. status = ocfs2_blockcheck_stats_debugfs_install(
  975. &osb->osb_ecc_stats,
  976. osb->osb_debug_root);
  977. if (status) {
  978. mlog(ML_ERROR,
  979. "Unable to create blockcheck statistics "
  980. "files\n");
  981. goto read_super_error;
  982. }
  983. }
  984. status = ocfs2_mount_volume(sb);
  985. if (osb->root_inode)
  986. inode = igrab(osb->root_inode);
  987. if (status < 0)
  988. goto read_super_error;
  989. if (!inode) {
  990. status = -EIO;
  991. mlog_errno(status);
  992. goto read_super_error;
  993. }
  994. root = d_alloc_root(inode);
  995. if (!root) {
  996. status = -ENOMEM;
  997. mlog_errno(status);
  998. goto read_super_error;
  999. }
  1000. sb->s_root = root;
  1001. ocfs2_complete_mount_recovery(osb);
  1002. if (ocfs2_mount_local(osb))
  1003. snprintf(nodestr, sizeof(nodestr), "local");
  1004. else
  1005. snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
  1006. printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
  1007. "with %s data mode.\n",
  1008. osb->dev_str, nodestr, osb->slot_num,
  1009. osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
  1010. "ordered");
  1011. atomic_set(&osb->vol_state, VOLUME_MOUNTED);
  1012. wake_up(&osb->osb_mount_event);
  1013. /* Now we can initialize quotas because we can afford to wait
  1014. * for cluster locks recovery now. That also means that truncation
  1015. * log recovery can happen but that waits for proper quota setup */
  1016. if (!(sb->s_flags & MS_RDONLY)) {
  1017. status = ocfs2_enable_quotas(osb);
  1018. if (status < 0) {
  1019. /* We have to err-out specially here because
  1020. * s_root is already set */
  1021. mlog_errno(status);
  1022. atomic_set(&osb->vol_state, VOLUME_DISABLED);
  1023. wake_up(&osb->osb_mount_event);
  1024. mlog_exit(status);
  1025. return status;
  1026. }
  1027. }
  1028. ocfs2_complete_quota_recovery(osb);
  1029. /* Now we wake up again for processes waiting for quotas */
  1030. atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS);
  1031. wake_up(&osb->osb_mount_event);
  1032. /* Start this when the mount is almost sure of being successful */
  1033. ocfs2_orphan_scan_start(osb);
  1034. mlog_exit(status);
  1035. return status;
  1036. read_super_error:
  1037. brelse(bh);
  1038. if (inode)
  1039. iput(inode);
  1040. if (osb) {
  1041. atomic_set(&osb->vol_state, VOLUME_DISABLED);
  1042. wake_up(&osb->osb_mount_event);
  1043. ocfs2_dismount_volume(sb, 1);
  1044. }
  1045. mlog_exit(status);
  1046. return status;
  1047. }
  1048. static int ocfs2_get_sb(struct file_system_type *fs_type,
  1049. int flags,
  1050. const char *dev_name,
  1051. void *data,
  1052. struct vfsmount *mnt)
  1053. {
  1054. return get_sb_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super,
  1055. mnt);
  1056. }
  1057. static void ocfs2_kill_sb(struct super_block *sb)
  1058. {
  1059. struct ocfs2_super *osb = OCFS2_SB(sb);
  1060. /* Failed mount? */
  1061. if (!osb || atomic_read(&osb->vol_state) == VOLUME_DISABLED)
  1062. goto out;
  1063. /* Prevent further queueing of inode drop events */
  1064. spin_lock(&dentry_list_lock);
  1065. ocfs2_set_osb_flag(osb, OCFS2_OSB_DROP_DENTRY_LOCK_IMMED);
  1066. spin_unlock(&dentry_list_lock);
  1067. /* Wait for work to finish and/or remove it */
  1068. cancel_work_sync(&osb->dentry_lock_work);
  1069. out:
  1070. kill_block_super(sb);
  1071. }
  1072. static struct file_system_type ocfs2_fs_type = {
  1073. .owner = THIS_MODULE,
  1074. .name = "ocfs2",
  1075. .get_sb = ocfs2_get_sb, /* is this called when we mount
  1076. * the fs? */
  1077. .kill_sb = ocfs2_kill_sb,
  1078. .fs_flags = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE,
  1079. .next = NULL
  1080. };
  1081. static int ocfs2_check_set_options(struct super_block *sb,
  1082. struct mount_options *options)
  1083. {
  1084. if (options->mount_opt & OCFS2_MOUNT_USRQUOTA &&
  1085. !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
  1086. OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
  1087. mlog(ML_ERROR, "User quotas were requested, but this "
  1088. "filesystem does not have the feature enabled.\n");
  1089. return 0;
  1090. }
  1091. if (options->mount_opt & OCFS2_MOUNT_GRPQUOTA &&
  1092. !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
  1093. OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
  1094. mlog(ML_ERROR, "Group quotas were requested, but this "
  1095. "filesystem does not have the feature enabled.\n");
  1096. return 0;
  1097. }
  1098. if (options->mount_opt & OCFS2_MOUNT_POSIX_ACL &&
  1099. !OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR)) {
  1100. mlog(ML_ERROR, "ACL support requested but extended attributes "
  1101. "feature is not enabled\n");
  1102. return 0;
  1103. }
  1104. /* No ACL setting specified? Use XATTR feature... */
  1105. if (!(options->mount_opt & (OCFS2_MOUNT_POSIX_ACL |
  1106. OCFS2_MOUNT_NO_POSIX_ACL))) {
  1107. if (OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR))
  1108. options->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
  1109. else
  1110. options->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
  1111. }
  1112. return 1;
  1113. }
  1114. static int ocfs2_parse_options(struct super_block *sb,
  1115. char *options,
  1116. struct mount_options *mopt,
  1117. int is_remount)
  1118. {
  1119. int status;
  1120. char *p;
  1121. mlog_entry("remount: %d, options: \"%s\"\n", is_remount,
  1122. options ? options : "(none)");
  1123. mopt->commit_interval = 0;
  1124. mopt->mount_opt = 0;
  1125. mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
  1126. mopt->slot = OCFS2_INVALID_SLOT;
  1127. mopt->localalloc_opt = OCFS2_DEFAULT_LOCAL_ALLOC_SIZE;
  1128. mopt->cluster_stack[0] = '\0';
  1129. if (!options) {
  1130. status = 1;
  1131. goto bail;
  1132. }
  1133. while ((p = strsep(&options, ",")) != NULL) {
  1134. int token, option;
  1135. substring_t args[MAX_OPT_ARGS];
  1136. if (!*p)
  1137. continue;
  1138. token = match_token(p, tokens, args);
  1139. switch (token) {
  1140. case Opt_hb_local:
  1141. mopt->mount_opt |= OCFS2_MOUNT_HB_LOCAL;
  1142. break;
  1143. case Opt_hb_none:
  1144. mopt->mount_opt &= ~OCFS2_MOUNT_HB_LOCAL;
  1145. break;
  1146. case Opt_barrier:
  1147. if (match_int(&args[0], &option)) {
  1148. status = 0;
  1149. goto bail;
  1150. }
  1151. if (option)
  1152. mopt->mount_opt |= OCFS2_MOUNT_BARRIER;
  1153. else
  1154. mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER;
  1155. break;
  1156. case Opt_intr:
  1157. mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR;
  1158. break;
  1159. case Opt_nointr:
  1160. mopt->mount_opt |= OCFS2_MOUNT_NOINTR;
  1161. break;
  1162. case Opt_err_panic:
  1163. mopt->mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
  1164. break;
  1165. case Opt_err_ro:
  1166. mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
  1167. break;
  1168. case Opt_data_ordered:
  1169. mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK;
  1170. break;
  1171. case Opt_data_writeback:
  1172. mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
  1173. break;
  1174. case Opt_user_xattr:
  1175. mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
  1176. break;
  1177. case Opt_nouser_xattr:
  1178. mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
  1179. break;
  1180. case Opt_atime_quantum:
  1181. if (match_int(&args[0], &option)) {
  1182. status = 0;
  1183. goto bail;
  1184. }
  1185. if (option >= 0)
  1186. mopt->atime_quantum = option;
  1187. break;
  1188. case Opt_slot:
  1189. option = 0;
  1190. if (match_int(&args[0], &option)) {
  1191. status = 0;
  1192. goto bail;
  1193. }
  1194. if (option)
  1195. mopt->slot = (s16)option;
  1196. break;
  1197. case Opt_commit:
  1198. option = 0;
  1199. if (match_int(&args[0], &option)) {
  1200. status = 0;
  1201. goto bail;
  1202. }
  1203. if (option < 0)
  1204. return 0;
  1205. if (option == 0)
  1206. option = JBD2_DEFAULT_MAX_COMMIT_AGE;
  1207. mopt->commit_interval = HZ * option;
  1208. break;
  1209. case Opt_localalloc:
  1210. option = 0;
  1211. if (match_int(&args[0], &option)) {
  1212. status = 0;
  1213. goto bail;
  1214. }
  1215. if (option >= 0 && (option <= ocfs2_local_alloc_size(sb) * 8))
  1216. mopt->localalloc_opt = option;
  1217. break;
  1218. case Opt_localflocks:
  1219. /*
  1220. * Changing this during remount could race
  1221. * flock() requests, or "unbalance" existing
  1222. * ones (e.g., a lock is taken in one mode but
  1223. * dropped in the other). If users care enough
  1224. * to flip locking modes during remount, we
  1225. * could add a "local" flag to individual
  1226. * flock structures for proper tracking of
  1227. * state.
  1228. */
  1229. if (!is_remount)
  1230. mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
  1231. break;
  1232. case Opt_stack:
  1233. /* Check both that the option we were passed
  1234. * is of the right length and that it is a proper
  1235. * string of the right length.
  1236. */
  1237. if (((args[0].to - args[0].from) !=
  1238. OCFS2_STACK_LABEL_LEN) ||
  1239. (strnlen(args[0].from,
  1240. OCFS2_STACK_LABEL_LEN) !=
  1241. OCFS2_STACK_LABEL_LEN)) {
  1242. mlog(ML_ERROR,
  1243. "Invalid cluster_stack option\n");
  1244. status = 0;
  1245. goto bail;
  1246. }
  1247. memcpy(mopt->cluster_stack, args[0].from,
  1248. OCFS2_STACK_LABEL_LEN);
  1249. mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
  1250. break;
  1251. case Opt_inode64:
  1252. mopt->mount_opt |= OCFS2_MOUNT_INODE64;
  1253. break;
  1254. case Opt_usrquota:
  1255. mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA;
  1256. break;
  1257. case Opt_grpquota:
  1258. mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA;
  1259. break;
  1260. case Opt_acl:
  1261. mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
  1262. mopt->mount_opt &= ~OCFS2_MOUNT_NO_POSIX_ACL;
  1263. break;
  1264. case Opt_noacl:
  1265. mopt->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
  1266. mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
  1267. break;
  1268. default:
  1269. mlog(ML_ERROR,
  1270. "Unrecognized mount option \"%s\" "
  1271. "or missing value\n", p);
  1272. status = 0;
  1273. goto bail;
  1274. }
  1275. }
  1276. status = 1;
  1277. bail:
  1278. mlog_exit(status);
  1279. return status;
  1280. }
  1281. static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
  1282. {
  1283. struct ocfs2_super *osb = OCFS2_SB(mnt->mnt_sb);
  1284. unsigned long opts = osb->s_mount_opt;
  1285. unsigned int local_alloc_megs;
  1286. if (opts & OCFS2_MOUNT_HB_LOCAL)
  1287. seq_printf(s, ",_netdev,heartbeat=local");
  1288. else
  1289. seq_printf(s, ",heartbeat=none");
  1290. if (opts & OCFS2_MOUNT_NOINTR)
  1291. seq_printf(s, ",nointr");
  1292. if (opts & OCFS2_MOUNT_DATA_WRITEBACK)
  1293. seq_printf(s, ",data=writeback");
  1294. else
  1295. seq_printf(s, ",data=ordered");
  1296. if (opts & OCFS2_MOUNT_BARRIER)
  1297. seq_printf(s, ",barrier=1");
  1298. if (opts & OCFS2_MOUNT_ERRORS_PANIC)
  1299. seq_printf(s, ",errors=panic");
  1300. else
  1301. seq_printf(s, ",errors=remount-ro");
  1302. if (osb->preferred_slot != OCFS2_INVALID_SLOT)
  1303. seq_printf(s, ",preferred_slot=%d", osb->preferred_slot);
  1304. if (osb->s_atime_quantum != OCFS2_DEFAULT_ATIME_QUANTUM)
  1305. seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum);
  1306. if (osb->osb_commit_interval)
  1307. seq_printf(s, ",commit=%u",
  1308. (unsigned) (osb->osb_commit_interval / HZ));
  1309. local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits);
  1310. if (local_alloc_megs != OCFS2_DEFAULT_LOCAL_ALLOC_SIZE)
  1311. seq_printf(s, ",localalloc=%d", local_alloc_megs);
  1312. if (opts & OCFS2_MOUNT_LOCALFLOCKS)
  1313. seq_printf(s, ",localflocks,");
  1314. if (osb->osb_cluster_stack[0])
  1315. seq_printf(s, ",cluster_stack=%.*s", OCFS2_STACK_LABEL_LEN,
  1316. osb->osb_cluster_stack);
  1317. if (opts & OCFS2_MOUNT_USRQUOTA)
  1318. seq_printf(s, ",usrquota");
  1319. if (opts & OCFS2_MOUNT_GRPQUOTA)
  1320. seq_printf(s, ",grpquota");
  1321. if (opts & OCFS2_MOUNT_NOUSERXATTR)
  1322. seq_printf(s, ",nouser_xattr");
  1323. else
  1324. seq_printf(s, ",user_xattr");
  1325. if (opts & OCFS2_MOUNT_INODE64)
  1326. seq_printf(s, ",inode64");
  1327. if (opts & OCFS2_MOUNT_POSIX_ACL)
  1328. seq_printf(s, ",acl");
  1329. else
  1330. seq_printf(s, ",noacl");
  1331. return 0;
  1332. }
  1333. static int __init ocfs2_init(void)
  1334. {
  1335. int status;
  1336. mlog_entry_void();
  1337. ocfs2_print_version();
  1338. status = init_ocfs2_uptodate_cache();
  1339. if (status < 0) {
  1340. mlog_errno(status);
  1341. goto leave;
  1342. }
  1343. status = ocfs2_initialize_mem_caches();
  1344. if (status < 0) {
  1345. mlog_errno(status);
  1346. goto leave;
  1347. }
  1348. ocfs2_wq = create_singlethread_workqueue("ocfs2_wq");
  1349. if (!ocfs2_wq) {
  1350. status = -ENOMEM;
  1351. goto leave;
  1352. }
  1353. ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
  1354. if (!ocfs2_debugfs_root) {
  1355. status = -EFAULT;
  1356. mlog(ML_ERROR, "Unable to create ocfs2 debugfs root.\n");
  1357. }
  1358. status = ocfs2_quota_setup();
  1359. if (status)
  1360. goto leave;
  1361. ocfs2_set_locking_protocol();
  1362. status = register_quota_format(&ocfs2_quota_format);
  1363. leave:
  1364. if (status < 0) {
  1365. ocfs2_quota_shutdown();
  1366. ocfs2_free_mem_caches();
  1367. exit_ocfs2_uptodate_cache();
  1368. }
  1369. mlog_exit(status);
  1370. if (status >= 0) {
  1371. return register_filesystem(&ocfs2_fs_type);
  1372. } else
  1373. return -1;
  1374. }
  1375. static void __exit ocfs2_exit(void)
  1376. {
  1377. mlog_entry_void();
  1378. ocfs2_quota_shutdown();
  1379. if (ocfs2_wq) {
  1380. flush_workqueue(ocfs2_wq);
  1381. destroy_workqueue(ocfs2_wq);
  1382. }
  1383. unregister_quota_format(&ocfs2_quota_format);
  1384. debugfs_remove(ocfs2_debugfs_root);
  1385. ocfs2_free_mem_caches();
  1386. unregister_filesystem(&ocfs2_fs_type);
  1387. exit_ocfs2_uptodate_cache();
  1388. mlog_exit_void();
  1389. }
  1390. static void ocfs2_put_super(struct super_block *sb)
  1391. {
  1392. mlog_entry("(0x%p)\n", sb);
  1393. lock_kernel();
  1394. ocfs2_sync_blockdev(sb);
  1395. ocfs2_dismount_volume(sb, 0);
  1396. unlock_kernel();
  1397. mlog_exit_void();
  1398. }
  1399. static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
  1400. {
  1401. struct ocfs2_super *osb;
  1402. u32 numbits, freebits;
  1403. int status;
  1404. struct ocfs2_dinode *bm_lock;
  1405. struct buffer_head *bh = NULL;
  1406. struct inode *inode = NULL;
  1407. mlog_entry("(%p, %p)\n", dentry->d_sb, buf);
  1408. osb = OCFS2_SB(dentry->d_sb);
  1409. inode = ocfs2_get_system_file_inode(osb,
  1410. GLOBAL_BITMAP_SYSTEM_INODE,
  1411. OCFS2_INVALID_SLOT);
  1412. if (!inode) {
  1413. mlog(ML_ERROR, "failed to get bitmap inode\n");
  1414. status = -EIO;
  1415. goto bail;
  1416. }
  1417. status = ocfs2_inode_lock(inode, &bh, 0);
  1418. if (status < 0) {
  1419. mlog_errno(status);
  1420. goto bail;
  1421. }
  1422. bm_lock = (struct ocfs2_dinode *) bh->b_data;
  1423. numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total);
  1424. freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used);
  1425. buf->f_type = OCFS2_SUPER_MAGIC;
  1426. buf->f_bsize = dentry->d_sb->s_blocksize;
  1427. buf->f_namelen = OCFS2_MAX_FILENAME_LEN;
  1428. buf->f_blocks = ((sector_t) numbits) *
  1429. (osb->s_clustersize >> osb->sb->s_blocksize_bits);
  1430. buf->f_bfree = ((sector_t) freebits) *
  1431. (osb->s_clustersize >> osb->sb->s_blocksize_bits);
  1432. buf->f_bavail = buf->f_bfree;
  1433. buf->f_files = numbits;
  1434. buf->f_ffree = freebits;
  1435. brelse(bh);
  1436. ocfs2_inode_unlock(inode, 0);
  1437. status = 0;
  1438. bail:
  1439. if (inode)
  1440. iput(inode);
  1441. mlog_exit(status);
  1442. return status;
  1443. }
  1444. static void ocfs2_inode_init_once(void *data)
  1445. {
  1446. struct ocfs2_inode_info *oi = data;
  1447. oi->ip_flags = 0;
  1448. oi->ip_open_count = 0;
  1449. spin_lock_init(&oi->ip_lock);
  1450. ocfs2_extent_map_init(&oi->vfs_inode);
  1451. INIT_LIST_HEAD(&oi->ip_io_markers);
  1452. oi->ip_dir_start_lookup = 0;
  1453. init_rwsem(&oi->ip_alloc_sem);
  1454. init_rwsem(&oi->ip_xattr_sem);
  1455. mutex_init(&oi->ip_io_mutex);
  1456. oi->ip_blkno = 0ULL;
  1457. oi->ip_clusters = 0;
  1458. ocfs2_lock_res_init_once(&oi->ip_rw_lockres);
  1459. ocfs2_lock_res_init_once(&oi->ip_inode_lockres);
  1460. ocfs2_lock_res_init_once(&oi->ip_open_lockres);
  1461. ocfs2_metadata_cache_init(INODE_CACHE(&oi->vfs_inode),
  1462. &ocfs2_inode_caching_ops);
  1463. inode_init_once(&oi->vfs_inode);
  1464. }
  1465. static int ocfs2_initialize_mem_caches(void)
  1466. {
  1467. ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache",
  1468. sizeof(struct ocfs2_inode_info),
  1469. 0,
  1470. (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
  1471. SLAB_MEM_SPREAD),
  1472. ocfs2_inode_init_once);
  1473. ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache",
  1474. sizeof(struct ocfs2_dquot),
  1475. 0,
  1476. (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
  1477. SLAB_MEM_SPREAD),
  1478. NULL);
  1479. ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache",
  1480. sizeof(struct ocfs2_quota_chunk),
  1481. 0,
  1482. (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
  1483. NULL);
  1484. if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
  1485. !ocfs2_qf_chunk_cachep) {
  1486. if (ocfs2_inode_cachep)
  1487. kmem_cache_destroy(ocfs2_inode_cachep);
  1488. if (ocfs2_dquot_cachep)
  1489. kmem_cache_destroy(ocfs2_dquot_cachep);
  1490. if (ocfs2_qf_chunk_cachep)
  1491. kmem_cache_destroy(ocfs2_qf_chunk_cachep);
  1492. return -ENOMEM;
  1493. }
  1494. return 0;
  1495. }
  1496. static void ocfs2_free_mem_caches(void)
  1497. {
  1498. if (ocfs2_inode_cachep)
  1499. kmem_cache_destroy(ocfs2_inode_cachep);
  1500. ocfs2_inode_cachep = NULL;
  1501. if (ocfs2_dquot_cachep)
  1502. kmem_cache_destroy(ocfs2_dquot_cachep);
  1503. ocfs2_dquot_cachep = NULL;
  1504. if (ocfs2_qf_chunk_cachep)
  1505. kmem_cache_destroy(ocfs2_qf_chunk_cachep);
  1506. ocfs2_qf_chunk_cachep = NULL;
  1507. }
  1508. static int ocfs2_get_sector(struct super_block *sb,
  1509. struct buffer_head **bh,
  1510. int block,
  1511. int sect_size)
  1512. {
  1513. if (!sb_set_blocksize(sb, sect_size)) {
  1514. mlog(ML_ERROR, "unable to set blocksize\n");
  1515. return -EIO;
  1516. }
  1517. *bh = sb_getblk(sb, block);
  1518. if (!*bh) {
  1519. mlog_errno(-EIO);
  1520. return -EIO;
  1521. }
  1522. lock_buffer(*bh);
  1523. if (!buffer_dirty(*bh))
  1524. clear_buffer_uptodate(*bh);
  1525. unlock_buffer(*bh);
  1526. ll_rw_block(READ, 1, bh);
  1527. wait_on_buffer(*bh);
  1528. if (!buffer_uptodate(*bh)) {
  1529. mlog_errno(-EIO);
  1530. brelse(*bh);
  1531. *bh = NULL;
  1532. return -EIO;
  1533. }
  1534. return 0;
  1535. }
  1536. static int ocfs2_mount_volume(struct super_block *sb)
  1537. {
  1538. int status = 0;
  1539. int unlock_super = 0;
  1540. struct ocfs2_super *osb = OCFS2_SB(sb);
  1541. mlog_entry_void();
  1542. if (ocfs2_is_hard_readonly(osb))
  1543. goto leave;
  1544. status = ocfs2_dlm_init(osb);
  1545. if (status < 0) {
  1546. mlog_errno(status);
  1547. goto leave;
  1548. }
  1549. status = ocfs2_super_lock(osb, 1);
  1550. if (status < 0) {
  1551. mlog_errno(status);
  1552. goto leave;
  1553. }
  1554. unlock_super = 1;
  1555. /* This will load up the node map and add ourselves to it. */
  1556. status = ocfs2_find_slot(osb);
  1557. if (status < 0) {
  1558. mlog_errno(status);
  1559. goto leave;
  1560. }
  1561. /* load all node-local system inodes */
  1562. status = ocfs2_init_local_system_inodes(osb);
  1563. if (status < 0) {
  1564. mlog_errno(status);
  1565. goto leave;
  1566. }
  1567. status = ocfs2_check_volume(osb);
  1568. if (status < 0) {
  1569. mlog_errno(status);
  1570. goto leave;
  1571. }
  1572. status = ocfs2_truncate_log_init(osb);
  1573. if (status < 0)
  1574. mlog_errno(status);
  1575. leave:
  1576. if (unlock_super)
  1577. ocfs2_super_unlock(osb, 1);
  1578. mlog_exit(status);
  1579. return status;
  1580. }
  1581. static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
  1582. {
  1583. int tmp, hangup_needed = 0;
  1584. struct ocfs2_super *osb = NULL;
  1585. char nodestr[8];
  1586. mlog_entry("(0x%p)\n", sb);
  1587. BUG_ON(!sb);
  1588. osb = OCFS2_SB(sb);
  1589. BUG_ON(!osb);
  1590. debugfs_remove(osb->osb_ctxt);
  1591. /*
  1592. * Flush inode dropping work queue so that deletes are
  1593. * performed while the filesystem is still working
  1594. */
  1595. ocfs2_drop_all_dl_inodes(osb);
  1596. /* Orphan scan should be stopped as early as possible */
  1597. ocfs2_orphan_scan_stop(osb);
  1598. ocfs2_disable_quotas(osb);
  1599. ocfs2_shutdown_local_alloc(osb);
  1600. ocfs2_truncate_log_shutdown(osb);
  1601. /* This will disable recovery and flush any recovery work. */
  1602. ocfs2_recovery_exit(osb);
  1603. ocfs2_journal_shutdown(osb);
  1604. ocfs2_sync_blockdev(sb);
  1605. ocfs2_purge_refcount_trees(osb);
  1606. /* No cluster connection means we've failed during mount, so skip
  1607. * all the steps which depended on that to complete. */
  1608. if (osb->cconn) {
  1609. tmp = ocfs2_super_lock(osb, 1);
  1610. if (tmp < 0) {
  1611. mlog_errno(tmp);
  1612. return;
  1613. }
  1614. }
  1615. if (osb->slot_num != OCFS2_INVALID_SLOT)
  1616. ocfs2_put_slot(osb);
  1617. if (osb->cconn)
  1618. ocfs2_super_unlock(osb, 1);
  1619. ocfs2_release_system_inodes(osb);
  1620. /*
  1621. * If we're dismounting due to mount error, mount.ocfs2 will clean
  1622. * up heartbeat. If we're a local mount, there is no heartbeat.
  1623. * If we failed before we got a uuid_str yet, we can't stop
  1624. * heartbeat. Otherwise, do it.
  1625. */
  1626. if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str)
  1627. hangup_needed = 1;
  1628. if (osb->cconn)
  1629. ocfs2_dlm_shutdown(osb, hangup_needed);
  1630. ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats);
  1631. debugfs_remove(osb->osb_debug_root);
  1632. if (hangup_needed)
  1633. ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));
  1634. atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
  1635. if (ocfs2_mount_local(osb))
  1636. snprintf(nodestr, sizeof(nodestr), "local");
  1637. else
  1638. snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
  1639. printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
  1640. osb->dev_str, nodestr);
  1641. ocfs2_delete_osb(osb);
  1642. kfree(osb);
  1643. sb->s_dev = 0;
  1644. sb->s_fs_info = NULL;
  1645. }
  1646. static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid,
  1647. unsigned uuid_bytes)
  1648. {
  1649. int i, ret;
  1650. char *ptr;
  1651. BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN);
  1652. osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL);
  1653. if (osb->uuid_str == NULL)
  1654. return -ENOMEM;
  1655. for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) {
  1656. /* print with null */
  1657. ret = snprintf(ptr, 3, "%02X", uuid[i]);
  1658. if (ret != 2) /* drop super cleans up */
  1659. return -EINVAL;
  1660. /* then only advance past the last char */
  1661. ptr += 2;
  1662. }
  1663. return 0;
  1664. }
  1665. static int ocfs2_initialize_super(struct super_block *sb,
  1666. struct buffer_head *bh,
  1667. int sector_size,
  1668. struct ocfs2_blockcheck_stats *stats)
  1669. {
  1670. int status;
  1671. int i, cbits, bbits;
  1672. struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
  1673. struct inode *inode = NULL;
  1674. struct ocfs2_journal *journal;
  1675. __le32 uuid_net_key;
  1676. struct ocfs2_super *osb;
  1677. mlog_entry_void();
  1678. osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL);
  1679. if (!osb) {
  1680. status = -ENOMEM;
  1681. mlog_errno(status);
  1682. goto bail;
  1683. }
  1684. sb->s_fs_info = osb;
  1685. sb->s_op = &ocfs2_sops;
  1686. sb->s_export_op = &ocfs2_export_ops;
  1687. sb->s_qcop = &ocfs2_quotactl_ops;
  1688. sb->dq_op = &ocfs2_quota_operations;
  1689. sb->s_xattr = ocfs2_xattr_handlers;
  1690. sb->s_time_gran = 1;
  1691. sb->s_flags |= MS_NOATIME;
  1692. /* this is needed to support O_LARGEFILE */
  1693. cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
  1694. bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
  1695. sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
  1696. osb->osb_dx_mask = (1 << (cbits - bbits)) - 1;
  1697. for (i = 0; i < 3; i++)
  1698. osb->osb_dx_seed[i] = le32_to_cpu(di->id2.i_super.s_dx_seed[i]);
  1699. osb->osb_dx_seed[3] = le32_to_cpu(di->id2.i_super.s_uuid_hash);
  1700. osb->sb = sb;
  1701. /* Save off for ocfs2_rw_direct */
  1702. osb->s_sectsize_bits = blksize_bits(sector_size);
  1703. BUG_ON(!osb->s_sectsize_bits);
  1704. spin_lock_init(&osb->dc_task_lock);
  1705. init_waitqueue_head(&osb->dc_event);
  1706. osb->dc_work_sequence = 0;
  1707. osb->dc_wake_sequence = 0;
  1708. INIT_LIST_HEAD(&osb->blocked_lock_list);
  1709. osb->blocked_lock_count = 0;
  1710. spin_lock_init(&osb->osb_lock);
  1711. spin_lock_init(&osb->osb_xattr_lock);
  1712. ocfs2_init_inode_steal_slot(osb);
  1713. atomic_set(&osb->alloc_stats.moves, 0);
  1714. atomic_set(&osb->alloc_stats.local_data, 0);
  1715. atomic_set(&osb->alloc_stats.bitmap_data, 0);
  1716. atomic_set(&osb->alloc_stats.bg_allocs, 0);
  1717. atomic_set(&osb->alloc_stats.bg_extends, 0);
  1718. /* Copy the blockcheck stats from the superblock probe */
  1719. osb->osb_ecc_stats = *stats;
  1720. ocfs2_init_node_maps(osb);
  1721. snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
  1722. MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
  1723. ocfs2_orphan_scan_init(osb);
  1724. status = ocfs2_recovery_init(osb);
  1725. if (status) {
  1726. mlog(ML_ERROR, "Unable to initialize recovery state\n");
  1727. mlog_errno(status);
  1728. goto bail;
  1729. }
  1730. init_waitqueue_head(&osb->checkpoint_event);
  1731. atomic_set(&osb->needs_checkpoint, 0);
  1732. osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
  1733. osb->slot_num = OCFS2_INVALID_SLOT;
  1734. osb->s_xattr_inline_size = le16_to_cpu(
  1735. di->id2.i_super.s_xattr_inline_size);
  1736. osb->local_alloc_state = OCFS2_LA_UNUSED;
  1737. osb->local_alloc_bh = NULL;
  1738. INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker);
  1739. init_waitqueue_head(&osb->osb_mount_event);
  1740. osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL);
  1741. if (!osb->vol_label) {
  1742. mlog(ML_ERROR, "unable to alloc vol label\n");
  1743. status = -ENOMEM;
  1744. goto bail;
  1745. }
  1746. osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
  1747. if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
  1748. mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
  1749. osb->max_slots);
  1750. status = -EINVAL;
  1751. goto bail;
  1752. }
  1753. mlog(0, "max_slots for this device: %u\n", osb->max_slots);
  1754. osb->slot_recovery_generations =
  1755. kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
  1756. GFP_KERNEL);
  1757. if (!osb->slot_recovery_generations) {
  1758. status = -ENOMEM;
  1759. mlog_errno(status);
  1760. goto bail;
  1761. }
  1762. init_waitqueue_head(&osb->osb_wipe_event);
  1763. osb->osb_orphan_wipes = kcalloc(osb->max_slots,
  1764. sizeof(*osb->osb_orphan_wipes),
  1765. GFP_KERNEL);
  1766. if (!osb->osb_orphan_wipes) {
  1767. status = -ENOMEM;
  1768. mlog_errno(status);
  1769. goto bail;
  1770. }
  1771. osb->osb_rf_lock_tree = RB_ROOT;
  1772. osb->s_feature_compat =
  1773. le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat);
  1774. osb->s_feature_ro_compat =
  1775. le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat);
  1776. osb->s_feature_incompat =
  1777. le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat);
  1778. if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) {
  1779. mlog(ML_ERROR, "couldn't mount because of unsupported "
  1780. "optional features (%x).\n", i);
  1781. status = -EINVAL;
  1782. goto bail;
  1783. }
  1784. if (!(osb->sb->s_flags & MS_RDONLY) &&
  1785. (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) {
  1786. mlog(ML_ERROR, "couldn't mount RDWR because of "
  1787. "unsupported optional features (%x).\n", i);
  1788. status = -EINVAL;
  1789. goto bail;
  1790. }
  1791. if (ocfs2_userspace_stack(osb)) {
  1792. memcpy(osb->osb_cluster_stack,
  1793. OCFS2_RAW_SB(di)->s_cluster_info.ci_stack,
  1794. OCFS2_STACK_LABEL_LEN);
  1795. osb->osb_cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
  1796. if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) {
  1797. mlog(ML_ERROR,
  1798. "couldn't mount because of an invalid "
  1799. "cluster stack label (%s) \n",
  1800. osb->osb_cluster_stack);
  1801. status = -EINVAL;
  1802. goto bail;
  1803. }
  1804. } else {
  1805. /* The empty string is identical with classic tools that
  1806. * don't know about s_cluster_info. */
  1807. osb->osb_cluster_stack[0] = '\0';
  1808. }
  1809. get_random_bytes(&osb->s_next_generation, sizeof(u32));
  1810. /* FIXME
  1811. * This should be done in ocfs2_journal_init(), but unknown
  1812. * ordering issues will cause the filesystem to crash.
  1813. * If anyone wants to figure out what part of the code
  1814. * refers to osb->journal before ocfs2_journal_init() is run,
  1815. * be my guest.
  1816. */
  1817. /* initialize our journal structure */
  1818. journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
  1819. if (!journal) {
  1820. mlog(ML_ERROR, "unable to alloc journal\n");
  1821. status = -ENOMEM;
  1822. goto bail;
  1823. }
  1824. osb->journal = journal;
  1825. journal->j_osb = osb;
  1826. atomic_set(&journal->j_num_trans, 0);
  1827. init_rwsem(&journal->j_trans_barrier);
  1828. init_waitqueue_head(&journal->j_checkpointed);
  1829. spin_lock_init(&journal->j_lock);
  1830. journal->j_trans_id = (unsigned long) 1;
  1831. INIT_LIST_HEAD(&journal->j_la_cleanups);
  1832. INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
  1833. journal->j_state = OCFS2_JOURNAL_FREE;
  1834. INIT_WORK(&osb->dentry_lock_work, ocfs2_drop_dl_inodes);
  1835. osb->dentry_lock_list = NULL;
  1836. /* get some pseudo constants for clustersize bits */
  1837. osb->s_clustersize_bits =
  1838. le32_to_cpu(di->id2.i_super.s_clustersize_bits);
  1839. osb->s_clustersize = 1 << osb->s_clustersize_bits;
  1840. mlog(0, "clusterbits=%d\n", osb->s_clustersize_bits);
  1841. if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE ||
  1842. osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) {
  1843. mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n",
  1844. osb->s_clustersize);
  1845. status = -EINVAL;
  1846. goto bail;
  1847. }
  1848. if (ocfs2_clusters_to_blocks(osb->sb, le32_to_cpu(di->i_clusters) - 1)
  1849. > (u32)~0UL) {
  1850. mlog(ML_ERROR, "Volume might try to write to blocks beyond "
  1851. "what jbd can address in 32 bits.\n");
  1852. status = -EINVAL;
  1853. goto bail;
  1854. }
  1855. if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid,
  1856. sizeof(di->id2.i_super.s_uuid))) {
  1857. mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n");
  1858. status = -ENOMEM;
  1859. goto bail;
  1860. }
  1861. memcpy(&uuid_net_key, di->id2.i_super.s_uuid, sizeof(uuid_net_key));
  1862. strncpy(osb->vol_label, di->id2.i_super.s_label, 63);
  1863. osb->vol_label[63] = '\0';
  1864. osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno);
  1865. osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno);
  1866. osb->first_cluster_group_blkno =
  1867. le64_to_cpu(di->id2.i_super.s_first_cluster_group);
  1868. osb->fs_generation = le32_to_cpu(di->i_fs_generation);
  1869. osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
  1870. mlog(0, "vol_label: %s\n", osb->vol_label);
  1871. mlog(0, "uuid: %s\n", osb->uuid_str);
  1872. mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n",
  1873. (unsigned long long)osb->root_blkno,
  1874. (unsigned long long)osb->system_dir_blkno);
  1875. osb->osb_dlm_debug = ocfs2_new_dlm_debug();
  1876. if (!osb->osb_dlm_debug) {
  1877. status = -ENOMEM;
  1878. mlog_errno(status);
  1879. goto bail;
  1880. }
  1881. atomic_set(&osb->vol_state, VOLUME_INIT);
  1882. /* load root, system_dir, and all global system inodes */
  1883. status = ocfs2_init_global_system_inodes(osb);
  1884. if (status < 0) {
  1885. mlog_errno(status);
  1886. goto bail;
  1887. }
  1888. /*
  1889. * global bitmap
  1890. */
  1891. inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE,
  1892. OCFS2_INVALID_SLOT);
  1893. if (!inode) {
  1894. status = -EINVAL;
  1895. mlog_errno(status);
  1896. goto bail;
  1897. }
  1898. osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno;
  1899. iput(inode);
  1900. osb->bitmap_cpg = ocfs2_group_bitmap_size(sb) * 8;
  1901. status = ocfs2_init_slot_info(osb);
  1902. if (status < 0) {
  1903. mlog_errno(status);
  1904. goto bail;
  1905. }
  1906. bail:
  1907. mlog_exit(status);
  1908. return status;
  1909. }
  1910. /*
  1911. * will return: -EAGAIN if it is ok to keep searching for superblocks
  1912. * -EINVAL if there is a bad superblock
  1913. * 0 on success
  1914. */
  1915. static int ocfs2_verify_volume(struct ocfs2_dinode *di,
  1916. struct buffer_head *bh,
  1917. u32 blksz,
  1918. struct ocfs2_blockcheck_stats *stats)
  1919. {
  1920. int status = -EAGAIN;
  1921. mlog_entry_void();
  1922. if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
  1923. strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
  1924. /* We have to do a raw check of the feature here */
  1925. if (le32_to_cpu(di->id2.i_super.s_feature_incompat) &
  1926. OCFS2_FEATURE_INCOMPAT_META_ECC) {
  1927. status = ocfs2_block_check_validate(bh->b_data,
  1928. bh->b_size,
  1929. &di->i_check,
  1930. stats);
  1931. if (status)
  1932. goto out;
  1933. }
  1934. status = -EINVAL;
  1935. if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) {
  1936. mlog(ML_ERROR, "found superblock with incorrect block "
  1937. "size: found %u, should be %u\n",
  1938. 1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits),
  1939. blksz);
  1940. } else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) !=
  1941. OCFS2_MAJOR_REV_LEVEL ||
  1942. le16_to_cpu(di->id2.i_super.s_minor_rev_level) !=
  1943. OCFS2_MINOR_REV_LEVEL) {
  1944. mlog(ML_ERROR, "found superblock with bad version: "
  1945. "found %u.%u, should be %u.%u\n",
  1946. le16_to_cpu(di->id2.i_super.s_major_rev_level),
  1947. le16_to_cpu(di->id2.i_super.s_minor_rev_level),
  1948. OCFS2_MAJOR_REV_LEVEL,
  1949. OCFS2_MINOR_REV_LEVEL);
  1950. } else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) {
  1951. mlog(ML_ERROR, "bad block number on superblock: "
  1952. "found %llu, should be %llu\n",
  1953. (unsigned long long)le64_to_cpu(di->i_blkno),
  1954. (unsigned long long)bh->b_blocknr);
  1955. } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 ||
  1956. le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) {
  1957. mlog(ML_ERROR, "bad cluster size found: %u\n",
  1958. 1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits));
  1959. } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) {
  1960. mlog(ML_ERROR, "bad root_blkno: 0\n");
  1961. } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) {
  1962. mlog(ML_ERROR, "bad system_dir_blkno: 0\n");
  1963. } else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) {
  1964. mlog(ML_ERROR,
  1965. "Superblock slots found greater than file system "
  1966. "maximum: found %u, max %u\n",
  1967. le16_to_cpu(di->id2.i_super.s_max_slots),
  1968. OCFS2_MAX_SLOTS);
  1969. } else {
  1970. /* found it! */
  1971. status = 0;
  1972. }
  1973. }
  1974. out:
  1975. mlog_exit(status);
  1976. return status;
  1977. }
  1978. static int ocfs2_check_volume(struct ocfs2_super *osb)
  1979. {
  1980. int status;
  1981. int dirty;
  1982. int local;
  1983. struct ocfs2_dinode *local_alloc = NULL; /* only used if we
  1984. * recover
  1985. * ourselves. */
  1986. mlog_entry_void();
  1987. /* Init our journal object. */
  1988. status = ocfs2_journal_init(osb->journal, &dirty);
  1989. if (status < 0) {
  1990. mlog(ML_ERROR, "Could not initialize journal!\n");
  1991. goto finally;
  1992. }
  1993. /* If the journal was unmounted cleanly then we don't want to
  1994. * recover anything. Otherwise, journal_load will do that
  1995. * dirty work for us :) */
  1996. if (!dirty) {
  1997. status = ocfs2_journal_wipe(osb->journal, 0);
  1998. if (status < 0) {
  1999. mlog_errno(status);
  2000. goto finally;
  2001. }
  2002. } else {
  2003. mlog(ML_NOTICE, "File system was not unmounted cleanly, "
  2004. "recovering volume.\n");
  2005. }
  2006. local = ocfs2_mount_local(osb);
  2007. /* will play back anything left in the journal. */
  2008. status = ocfs2_journal_load(osb->journal, local, dirty);
  2009. if (status < 0) {
  2010. mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status);
  2011. goto finally;
  2012. }
  2013. if (dirty) {
  2014. /* recover my local alloc if we didn't unmount cleanly. */
  2015. status = ocfs2_begin_local_alloc_recovery(osb,
  2016. osb->slot_num,
  2017. &local_alloc);
  2018. if (status < 0) {
  2019. mlog_errno(status);
  2020. goto finally;
  2021. }
  2022. /* we complete the recovery process after we've marked
  2023. * ourselves as mounted. */
  2024. }
  2025. mlog(0, "Journal loaded.\n");
  2026. status = ocfs2_load_local_alloc(osb);
  2027. if (status < 0) {
  2028. mlog_errno(status);
  2029. goto finally;
  2030. }
  2031. if (dirty) {
  2032. /* Recovery will be completed after we've mounted the
  2033. * rest of the volume. */
  2034. osb->dirty = 1;
  2035. osb->local_alloc_copy = local_alloc;
  2036. local_alloc = NULL;
  2037. }
  2038. /* go through each journal, trylock it and if you get the
  2039. * lock, and it's marked as dirty, set the bit in the recover
  2040. * map and launch a recovery thread for it. */
  2041. status = ocfs2_mark_dead_nodes(osb);
  2042. if (status < 0) {
  2043. mlog_errno(status);
  2044. goto finally;
  2045. }
  2046. status = ocfs2_compute_replay_slots(osb);
  2047. if (status < 0)
  2048. mlog_errno(status);
  2049. finally:
  2050. if (local_alloc)
  2051. kfree(local_alloc);
  2052. mlog_exit(status);
  2053. return status;
  2054. }
  2055. /*
  2056. * The routine gets called from dismount or close whenever a dismount on
  2057. * volume is requested and the osb open count becomes 1.
  2058. * It will remove the osb from the global list and also free up all the
  2059. * initialized resources and fileobject.
  2060. */
  2061. static void ocfs2_delete_osb(struct ocfs2_super *osb)
  2062. {
  2063. mlog_entry_void();
  2064. /* This function assumes that the caller has the main osb resource */
  2065. ocfs2_free_slot_info(osb);
  2066. kfree(osb->osb_orphan_wipes);
  2067. kfree(osb->slot_recovery_generations);
  2068. /* FIXME
  2069. * This belongs in journal shutdown, but because we have to
  2070. * allocate osb->journal at the start of ocfs2_initalize_osb(),
  2071. * we free it here.
  2072. */
  2073. kfree(osb->journal);
  2074. if (osb->local_alloc_copy)
  2075. kfree(osb->local_alloc_copy);
  2076. kfree(osb->uuid_str);
  2077. ocfs2_put_dlm_debug(osb->osb_dlm_debug);
  2078. memset(osb, 0, sizeof(struct ocfs2_super));
  2079. mlog_exit_void();
  2080. }
  2081. /* Put OCFS2 into a readonly state, or (if the user specifies it),
  2082. * panic(). We do not support continue-on-error operation. */
  2083. static void ocfs2_handle_error(struct super_block *sb)
  2084. {
  2085. struct ocfs2_super *osb = OCFS2_SB(sb);
  2086. if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC)
  2087. panic("OCFS2: (device %s): panic forced after error\n",
  2088. sb->s_id);
  2089. ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS);
  2090. if (sb->s_flags & MS_RDONLY &&
  2091. (ocfs2_is_soft_readonly(osb) ||
  2092. ocfs2_is_hard_readonly(osb)))
  2093. return;
  2094. printk(KERN_CRIT "File system is now read-only due to the potential "
  2095. "of on-disk corruption. Please run fsck.ocfs2 once the file "
  2096. "system is unmounted.\n");
  2097. sb->s_flags |= MS_RDONLY;
  2098. ocfs2_set_ro_flag(osb, 0);
  2099. }
  2100. static char error_buf[1024];
  2101. void __ocfs2_error(struct super_block *sb,
  2102. const char *function,
  2103. const char *fmt, ...)
  2104. {
  2105. va_list args;
  2106. va_start(args, fmt);
  2107. vsnprintf(error_buf, sizeof(error_buf), fmt, args);
  2108. va_end(args);
  2109. /* Not using mlog here because we want to show the actual
  2110. * function the error came from. */
  2111. printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %s\n",
  2112. sb->s_id, function, error_buf);
  2113. ocfs2_handle_error(sb);
  2114. }
  2115. /* Handle critical errors. This is intentionally more drastic than
  2116. * ocfs2_handle_error, so we only use for things like journal errors,
  2117. * etc. */
  2118. void __ocfs2_abort(struct super_block* sb,
  2119. const char *function,
  2120. const char *fmt, ...)
  2121. {
  2122. va_list args;
  2123. va_start(args, fmt);
  2124. vsnprintf(error_buf, sizeof(error_buf), fmt, args);
  2125. va_end(args);
  2126. printk(KERN_CRIT "OCFS2: abort (device %s): %s: %s\n",
  2127. sb->s_id, function, error_buf);
  2128. /* We don't have the cluster support yet to go straight to
  2129. * hard readonly in here. Until then, we want to keep
  2130. * ocfs2_abort() so that we can at least mark critical
  2131. * errors.
  2132. *
  2133. * TODO: This should abort the journal and alert other nodes
  2134. * that our slot needs recovery. */
  2135. /* Force a panic(). This stinks, but it's better than letting
  2136. * things continue without having a proper hard readonly
  2137. * here. */
  2138. if (!ocfs2_mount_local(OCFS2_SB(sb)))
  2139. OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
  2140. ocfs2_handle_error(sb);
  2141. }
  2142. module_init(ocfs2_init);
  2143. module_exit(ocfs2_exit);