Home > Articles > Security > Network Security

This chapter is from the book

15.6 Locking in UFS

UFS uses two basic types of locks: kmutex_t and krwlock_t. The workings of these synchronization primitives is covered in Chapter 17. UFS locks can be divided into eight categories:

  • Inode locks
  • Queue locks
  • ACL locks
  • VNODE locks
  • VFS locks
  • VOP_RWLOCK
  • ufs_iuniqtime_lock
  • Logging locks

15.6.1 UFS Lock Descriptions

Tables 15.2 through 15.9 describe the UFS locks in more detail.

Table 15.2. Inode Locks

Name

Type

Description

i_rwlock

krwlock_t

  • Serializes write requests. Allows reads to proceed in parallel. Serializes directory reads and updates.
  • Does not protect inode fields.
  • Indirectly protects block lists since it serializes allocations/deallocations in UFS.
  • Must be taken before starting UFS logging transactions if operating on a file; otherwise, taken after starting logging transaction.

i_contents

krwlock_t

  • Protects most fields in the inode.
  • When held as a writer, protects all the fields protected by the i_tlock.

i_tlock

kmutex_t

  • When held with the i_contents reader lock, protects the following inode fields: i_utime, i_ctime, i_mtime, i_flag, i_delayoff, i_delaylen, i_nextrio, i_writes, i_writer, i_mapcnt.
  • Also used as mutex for write throttling in UFS.
  • i_contents and i_tlock held together allows parallelism in updates.

i_hlock

kmutex_t

  • Inode hash lock.

Table 15.3. Inode Queue Locks

Name

Type

Description

ufs_scan_lock

kmutex_t

  • Synchronizes ufs_scan_inodes threads
  • ufs_update(), ufs_sync(), ufs_scan_inodes().
  • Needed because of global inode list.

ufs_q->uq_mutex

krwlock_t

  • Protects the two inode idle queues ufs_junk_iq and ufs_useful_iq.

ufs_hlock

kmutex_t

  • Used by the hlock thread. For more information, see man lockfs(1M), hardlock section.

ih_lock

kmutex_t

  • Protects the inode hash. The inode hash is global, per system, not per file system.

Table 15.4. Quota Queue Locks

Name

Type

Description

dq_cachelock

kmutex_t

  • Protects the quota cache list. Prerequisite before taking the dquot.dq_lock.

dq_freelock

kmutex_t

  • Protects the free quota list.

dq_rwlock

krwlock_t

  • Protects the entire quota subsystem.
  • Taken as writer when the quota subsystem is initialized. Taken as reader when we do not want entire quota subsystem to be quiesced.
  • As writer, allows updates to quota-related fields in the ufsvfs structure. Also protects the dquot file as writer to allow quota updates.
  • As reader, allows reads from the quota-related fields in the ufsvfs structure.

dqout.dq_lock

kmutex_t

  • Gives exclusive access to dquot struct.

Table 15.5. VNODE Locks

Name

Type

Description

v_lock

kmutex_t

  • Protects the vnode fields. Also used by VN_HOLD/VN_RELE.

Table 15.6. ACL Locks

Name

Type

Description

s_lock

krwlock_t

  • Protects the in-core shadow inode structure.

Table 15.7. VFS Locks

Name

Type

Description

vfs_lock

kmutex_t

  • Locks contents of file system and cylinder groups. Also protects fields of the vfs_dio.

vfs_dqrwlock

krwlock_t

  • Manages quota subsystem quiescence.
  • If held as writer, UFS quota subsystem may be experiencing changes in quotas, enabling/disabling of quotas, setting new quota limits.
  • Protects d_quot structure. This structure keeps track of all the enabled quotas per file system.
  • Important note: UFS shadow inodes that are used to hold ACL data and extended attribute directories are not counted against user quotas. Thus, this lock is not held for updates to these.
  • Reader held for this lock indicates to quota subsystem that major changes should not be occurring during that time.
  • Held when the i_contents writer lock is held, as described above, signifying that changes are occurring that affect user quotas.
  • Since UFS quotas can be enabled/disabled on the fly, this lock must be taken in all appropriate situations. It is not sufficient to check if the UFS quota subsystem is enabled before taking the lock.

ufsvfs_mutex

kmutex_t

  • Protects access to the list that links all UFS file system instances.
  • Updates lists as a part of the mount operation.
  • Allows synchronization of all UFS file systems.

Table 15.8. VOP_RWLOCK or ufs_rwlock

Name

Type

Description

ufs_rwlock()

function

  • Prevents concurrent reads and writes to a file.
  • Used by NFS when calling a VOP_READDIR, to prevent directory contents from changing.
  • NFS uses this lock to get attributes before and after a read or write to disable another operation from modifying the file.

Table 15.9. Logging Locks

Name

Type

Description

mtm_lock

kmutex_t

  • Protects mtm_taskq_sync_count (keeps track of the number of pending top_issue_sync requests) field in mt_map_t.

mtm_mutex

kmutex_t

  • Protects all the fields in the mt_map_t structure except mtm_mapext and mtm_refcnt.

mtm_rwlock

krwlock_t

  • Protects agenext_mapentry field.

un_log_mutex

kmutex_t

  • Allows one write to the log at a time. Part of ml_unit_t structure (in-core log data structure).

un_state_mutex

kmutex_t

  • Allows one log state update at a time.

15.6.2 Inode Lock Ordering

Now that we are all familiar with the several different types of locks available in UFS, let us put them in order as if we were to work on an inode. Lock ordering is critical, and any mistake will more than likely cause the system to deadlock, and may end up panicking it!

Figure 15.16 give us a quick overview of lock ordering specific to the inode.

ufs_15.gif

Figure 15.16 Inode Lock Ordering Precedence

15.6.3 UFS Lockfs Protocol

Along with basic inode locking, UFS also provides a mechanism to quiesce a file system for file system locking and for the forced unmounting of a file system. All VOPs (vnode operations) in UFS are required to follow the UFS lock protocol with ufs_lockfs_begin() and ufs_lockfs_end(), although the following functions purposely do not adhere to the tradition:

  • ufs_close
  • ufs_putpage
  • ufs_inactive
  • ufs_addmap
  • ufs_delmap
  • ufs_rwlock
  • ufs_rwunlock
  • ufs_poll

The basic principle here is that UFS supports various file system lock states (see list below) and each vnode operation must initiate the protocol by calling ufs_lockfs_begin() with an appropriate lock mask (a lock that this operation might grab while it is being processed) and end the protocol by calling ufs_lockfs_end before it returns. This way, UFS knows exactly how many vnode operations are in progress for the given file system by incrementing and decrementing the ul_vnops_cnt variable in the file-system-dependent ulockfs structure. If the file system is hard-locked, the thread gets an EIO error. If the file system is error-locked, then the thread is blocked.

Here are the file system locks and their actions.

  • Write lock. Suspends writes that would modify the file system. Access times are not kept while a file system is write-locked.
  • Name lock. Suspends accesses that could change or remove existing directories entries.
  • Delete lock. Suspends access that could remove directory entries.
  • Hard lock. Returns an error upon every access to the locked file system and cannot be unlocked. Hard-locked file systems can be unmounted. Hard lock supports forcible unmount.
  • Error lock. Blocks all local access to the file system and returns EWOULDBLOCK on all remote access. File systems are error-locked by UFS upon detection of internal inconsistency. They can only be unlocked after successful repair by fsck, which is usually done automatically. Error-locked file systems can be unmounted. Once the file system becomes clean, it can be upgraded to a hard lock.
  • Soft lock. Quiesces a file system.
  • Unlock. Awakens suspended accesses, releases existing locks, and flushes the file system.

While a vnode operation is being executed in UFS, a call can be made to another vnode function on the same UFS or a different UFS. This is called recursive VOP. The per-file system vnode operation counter is not incremented or decremented during recursive calls.

Here is the basic ordering to initiate and complete the lock protocol when operating on an inode in UFS.

1) Acquire i_rwlock (from the vnode layer in most cases).
2) Begin the UFS lock protocol by calling ufs_lockfs_begin().
3) Open UFS logging transactions if necessary now.
4) Acquire inode and quota locks (vfs_dqrwlock, i_contents, i_tlock, ...).
5) [work on inode]
6) Drop inode and quota locks (i_tlock, i_contents, vfs_dqrwlock, ...).
7) Close logging transactions.
8) End the UFS lock protocol by calling ufs_lockfs_end().
9) Release i_rwlock.

When working with directories, you need to make one minor change. i_rwlock is acquired after the logging transaction is initialized, and i_rwlock is released before the transaction is ended. Here are the steps.

1) Begin the UFS lock protocol by calling ufs_lockfs_begin().
2) Open UFS logging transactions if necessary now.
3) Acquire i_rwlock.
4) Acquire inode and quota locks (vfs_dqrwlock, i_contents, i_tlock, ...).
5) [work on inode]
6) Drop inode and quota locks (i_tlock, i_contents, vfs_dqrwlock, ...).
7) Release i_rwlock.
8) Close logging transactions.
9) End the UFS lock protocol by calling ufs_lockfs_end().

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020