/* * logfile.c - NTFS kernel journal handling. Part of the Linux-NTFS project. * * Copyright (c) 2002-2007 Anton Altaparmakov * * This program/include file is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as published * by the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program/include file is distributed in the hope that it will be * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program (in the main directory of the Linux-NTFS * distribution in the file COPYING); if not, write to the Free Software * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifdef NTFS_RW #include #include #include #include #include #include #include "attrib.h" #include "aops.h" #include "debug.h" #include "logfile.h" #include "malloc.h" #include "volume.h" #include "ntfs.h" /** * ntfs_check_restart_page_header - check the page header for consistency * @vi: $LogFile inode to which the restart page header belongs * @rp: restart page header to check * @pos: position in @vi at which the restart page header resides * * Check the restart page header @rp for consistency and return 'true' if it is * consistent and 'false' otherwise. * * This function only needs NTFS_BLOCK_SIZE bytes in @rp, i.e. it does not * require the full restart page. */ static bool ntfs_check_restart_page_header(struct inode *vi, RESTART_PAGE_HEADER *rp, s64 pos) { u32 logfile_system_page_size, logfile_log_page_size; u16 ra_ofs, usa_count, usa_ofs, usa_end = 0; bool have_usa = true; ntfs_debug("Entering."); /* * If the system or log page sizes are smaller than the ntfs block size * or either is not a power of 2 we cannot handle this log file. */ logfile_system_page_size = le32_to_cpu(rp->system_page_size); logfile_log_page_size = le32_to_cpu(rp->log_page_size); if (logfile_system_page_size < NTFS_BLOCK_SIZE || logfile_log_page_size < NTFS_BLOCK_SIZE || logfile_system_page_size & (logfile_system_page_size - 1) || !is_power_of_2(logfile_log_page_size)) { ntfs_error(vi->i_sb, "$LogFile uses unsupported page size."); return false; } /* * We must be either at !pos (1st restart page) or at pos = system page * size (2nd restart page). */ if (pos && pos != logfile_system_page_size) { ntfs_error(vi->i_sb, "Found restart area in incorrect " "position in $LogFile."); return false; } /* We only know how to handle version 1.1. */ if (sle16_to_cpu(rp->major_ver) != 1 || sle16_to_cpu(rp->minor_ver) != 1) { ntfs_error(vi->i_sb, "$LogFile version %i.%i is not " "supported. (This driver supports version " "1.1 only.)", (int)sle16_to_cpu(rp->major_ver), (int)sle16_to_cpu(rp->minor_ver)); return false; } /* * If chkdsk has been run the restart page may not be protected by an * update sequence array. */ if (ntfs_is_chkd_record(rp->magic) && !le16_to_cpu(rp->usa_count)) { have_usa = false; goto skip_usa_checks; } /* Verify the size of the update sequence array. */ usa_count = 1 + (logfile_system_page_size >> NTFS_BLOCK_SIZE_BITS); if (usa_count != le16_to_cpu(rp->usa_count)) { ntfs_error(vi->i_sb, "$LogFile restart page specifies " "inconsistent update sequence array count."); return false; } /* Verify the position of the update sequence array. */ usa_ofs = le16_to_cpu(rp->usa_ofs); usa_end = usa_ofs + usa_count * sizeof(u16); if (usa_ofs < sizeof(RESTART_PAGE_HEADER) || usa_end > NTFS_BLOCK_SIZE - sizeof(u16)) { ntfs_error(vi->i_sb, "$LogFile restart page specifies " "inconsistent update sequence array offset."); return false; } skip_usa_checks: /* * Verify the position of the restart area. It must be: * - aligned to 8-byte boundary, * - after the update sequence array, and * - within the system page size. */ ra_ofs = le16_to_cpu(rp->restart_area_offset); if (ra_ofs & 7 || (have_usa ? ra_ofs < usa_end : ra_ofs < sizeof(RESTART_PAGE_HEADER)) || ra_ofs > logfile_system_page_size) { ntfs_error(vi->i_sb, "$LogFile restart page specifies " "inconsistent restart area offset."); return false; } /* * Only restart pages modified by chkdsk are allowed to have chkdsk_lsn * set. */ if (!ntfs_is_chkd_record(rp->magic) && sle64_to_cpu(rp->chkdsk_lsn)) { ntfs_error(vi->i_sb, "$LogFile restart page is not modified " "by chkdsk but a chkdsk LSN is specified."); return false; } ntfs_debug("Done."); return true; } /** * ntfs_check_restart_area - check the restart area for consistency * @vi: $LogFile inode to which the restart page belongs * @rp: restart page whose restart area to check * * Check the restart area of the restart page @rp for consistency and return * 'true' if it is consistent and 'false' otherwise. * * This function assumes that the restart page header has already been * consistency checked. * * This function only needs NTFS_BLOCK_SIZE bytes in @rp, i.e. it does not * require the full restart page. */ static bool ntfs_check_restart_area(struct inode *vi, RESTART_PAGE_HEADER *rp) { u64 file_size; RESTART_AREA *ra; u16 ra_ofs, ra_len, ca_ofs; u8 fs_bits; ntfs_debug("Entering."); ra_ofs = le16_to_cpu(rp->restart_area_offset); ra = (RESTART_AREA*)((u8*)rp + ra_ofs); /* * Everything before ra->file_size must be before the first word * protected by an update sequence number. This ensures that it is * safe to access ra->client_array_offset. */ if (ra_ofs + offsetof(RESTART_AREA, file_size) > NTFS_BLOCK_SIZE - sizeof(u16)) { ntfs_error(vi->i_sb, "$LogFile restart area specifies " "inconsistent file offset."); return false; } /* * Now that we can access ra->client_array_offset, make sure everything * up to the log client array is before the first word protected by an * update sequence number. This ensures we can access all of the * restart area elements safely. Also, the client array offset must be * aligned to an 8-byte boundary. */ ca_ofs = le16_to_cpu(ra->client_array_offset); if (((ca_ofs + 7) & ~7) != ca_ofs || ra_ofs + ca_ofs > NTFS_BLOCK_SIZE - sizeof(u16)) { ntfs_error(vi->i_sb, "$LogFile restart area specifies " "inconsistent client array offset."); return false; } /* * The restart area must end within the system page size both when * calculated manually and as specified by ra->restart_area_length. * Also, the calculated length must not exceed the specified length. */ ra_len = ca_ofs + le16_to_cpu(ra->log_clients) * sizeof(LOG_CLIENT_RECORD); if (ra_ofs + ra_len > le32_to_cpu(rp->system_page_size) || ra_ofs + le16_to_cpu(ra->restart_area_length) > le32_to_cpu(rp->system_page_size) || ra_len > le16_to_cpu(ra->restart_area_length)) { ntfs_error(vi->i_sb, "$LogFile restart area is out of bounds " "of the system page size specified by the " "restart page header and/or the specified " "restart area length is inconsistent."); return false; } /* * The ra->client_free_list and ra->client_in_use_list must be either * LOGFILE_NO_CLIENT or less than ra->log_clients or they are * overflowing the client array. */ if ((ra->client_free_list != LOGFILE_NO_CLIENT && le16_to_cpu(ra->client_free_list) >= le16_to_cpu(ra->log_clients)) || (r
========================================
Setting Up Open Daylight Controller Node
========================================

For exemplary purpose, we assume:

* The hostname of Open Daylight Controller Node is ``opnfv-odl-controller``, and the host IP address is
  ``192.168.0.30``
* CentOS 7 is installed
* We use ``opnfv`` as username to login.
* Java 7 is installed in directory ``/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.85-2.6.1.2.el7_1.x86_64/``

**ODL-1**: Login to Open Daylight Controller Node with username ``opnfv``.

**ODL-2**: Download the ODL Lithium distribution from
``http://www.opendaylight.org/software/downloads``

.. code-block:: bash

    wget https://nexus.opendaylight.org/content/groups/public/org/opendaylight/integration/distribution-karaf/0.3.3-Lithium-SR3/distribution-karaf-0.3.3-Lithium-SR3.tar.gz

**ODL-3**: Extract the tar file

.. code-block:: bash

    tar -zxvf distribution-karaf-0.3.3-Lithium-SR3.tar.gz

**ODL-4**: Install Java7

.. code-block:: bash

    sudo yum install -y java-1.7.0-openjdk.x86_64

**ODL-5 (OPTIONAL)**: We are using ``iptables`` instead of
``firewalld`` but this is optional for the OpenDaylight Controller
Node. The objective is to allow all connections on the internal
private network (ens160). The same objective can be achieved using
firewalld as well. **If you intend to use firewalld, please skip this step and directly go to next step**:

.. code-block:: bash

    sudo systemctl stop firewalld.service
    sudo yum remove -y firewalld
    sudo yum install -y iptables-services
    sudo touch /etc/sysconfig/iptables
    sudo systemctl enable iptables.service
    sudo systemctl start iptables.service
    sudo iptables -I INPUT 1 -i ens160 -j ACCEPT
    sudo iptables -I INPUT -m state --state NEW -p tcp --dport 8181 -j ACCEPT # For ODL DLUX UI
    sudo iptables-save > /etc/sysconfig/iptables

**ODL-6**: Open a screen session.

.. code-block:: bash

    screen -S ODL_Controller

**ODL-7**: In the new screen session, change directory to where Open
Daylight is installed. Here we use ``odl`` directory name and
``Lithium SR3`` installation as an example.

.. code-block:: bash

    cd ~/odl/distribution-karaf-0.3.3-Lithium-SR3/bin

**ODL-8**: Set the JAVA environment variables.

.. code-block:: bash

    export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.85-2.6.1.2.el7_1.x86_64/jre
    export PATH=$PATH:/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.85-2.6.1.2.el7_1.x86_64/jre/bin

**ODL-9**: Run the ``karaf`` shell.

.. code-block:: bash

    ./karaf

**ODL-10**: You are now in the Karaf shell of Open Daylight. To explore the list of available features you can execute
``feature:list``. In order to enable Open Daylight with OpenStack, you have to load the ``odl-ovsdb-openstack``
feature.

.. code-block:: bash

    opendaylight-user@opnfv>feature:install odl-ovsdb-openstack

**ODL-11**: Verify that OVSDB feature is installed successfully.

.. code-block:: bash

    opendaylight-user@opnfv>feature:list -i | grep ovsdb
    odl-ovsdb-openstack | 1.1.1-Lithium-SR1       | x  | ovsdb-1.1.1-Lithium-SR1 | OpenDaylight :: OVSDB :: OpenStack Network Virtual
    odl-ovsdb-southbound-api  | 1.1.1-Lithium-SR1 | x  | odl-ovsdb-southbound-1.1.1-Lithium-SR1 | OpenDaylight :: southbound :: api
    odl-ovsdb-southbound-impl | 1.1.1-Lithium-SR1 | x  | odl-ovsdb-southbound-1.1.1-Lithium-SR1 | OpenDaylight :: southbound :: impl
    odl-ovsdb-southbound-impl-rest|1.1.1-Lithium-SR1 | x | odl-ovsdb-southbound-1.1.1-Lithium-SR1| OpenDaylight :: southbound :: impl :: REST
    odl-ovsdb-southbound-impl-ui  | 1.1.1-Lithium-SR1| x | odl-ovsdb-southbound-1.1.1-Lithium-SR1| OpenDaylight :: southbound :: impl :: UI
    opendaylight-user@opnfv>

**ODL-12**: To view the logs, you can use the following commands (or alternately the file data/log/karaf.log).

.. code-block:: bash

    opendaylight-user@opnfv>log:display
    opendaylight-user@opnfv>log:tail

**ODL-13**: To enable ODL DLUX UI, install the following features.
Then you can navigate to
``http://<opnfv-odl-controller IP address>:8181/index.html`` for DLUX
UI. The default user-name and password is ``admin/admin``.

.. code-block:: bash

    opendaylight-user@opnfv>feature:install odl-dlux-core

**ODL-14**: To exit out of screen session, please use the command ``CTRL+a`` followed by ``d``

**Note: Do not kill the screen session, it will terminate the ODL controller.**

At this moment, Open Daylight has been started successfully.
ntfs_error(vol->sb, "Did not find any restart pages in " "$LogFile and it was not empty."); return false; } /* If both restart pages were found, use the more recent one. */ if (rstr2_ph) { /* * If the second restart area is more recent, switch to it. * Otherwise just throw it away. */ if (rstr2_lsn > rstr1_lsn) { ntfs_debug("Using second restart page as it is more " "recent."); ntfs_free(rstr1_ph); rstr1_ph = rstr2_ph; /* rstr1_lsn = rstr2_lsn; */ } else { ntfs_debug("Using first restart page as it is more " "recent."); ntfs_free(rstr2_ph); } rstr2_ph = NULL; } /* All consistency checks passed. */ if (rp) *rp = rstr1_ph; else ntfs_free(rstr1_ph); ntfs_debug("Done."); return true; err_out: if (rstr1_ph) ntfs_free(rstr1_ph); return false; } /** * ntfs_is_logfile_clean - check in the journal if the volume is clean * @log_vi: struct inode of loaded journal $LogFile to check * @rp: copy of the current restart page * * Analyze the $LogFile journal and return 'true' if it indicates the volume was * shutdown cleanly and 'false' if not. * * At present we only look at the two restart pages and ignore the log record * pages. This is a little bit crude in that there will be a very small number * of cases where we think that a volume is dirty when in fact it is clean. * This should only affect volumes that have not been shutdown cleanly but did * not have any pending, non-check-pointed i/o, i.e. they were completely idle * at least for the five seconds preceding the unclean shutdown. * * This function assumes that the $LogFile journal has already been consistency * checked by a call to ntfs_check_logfile() and in particular if the $LogFile * is empty this function requires that NVolLogFileEmpty() is true otherwise an * empty volume will be reported as dirty. */ bool ntfs_is_logfile_clean(struct inode *log_vi, const RESTART_PAGE_HEADER *rp) { ntfs_volume *vol = NTFS_SB(log_vi->i_sb); RESTART_AREA *ra; ntfs_debug("Entering."); /* An empty $LogFile must have been clean before it got emptied. */ if (NVolLogFileEmpty(vol)) { ntfs_debug("Done. ($LogFile is empty.)"); return true; } BUG_ON(!rp); if (!ntfs_is_rstr_record(rp->magic) && !ntfs_is_chkd_record(rp->magic)) { ntfs_error(vol->sb, "Restart page buffer is invalid. This is " "probably a bug in that the $LogFile should " "have been consistency checked before calling " "this function."); return false; } ra = (RESTART_AREA*)((u8*)rp + le16_to_cpu(rp->restart_area_offset)); /* * If the $LogFile has active clients, i.e. it is open, and we do not * have the RESTART_VOLUME_IS_CLEAN bit set in the restart area flags, * we assume there was an unclean shutdown. */ if (ra->client_in_use_list != LOGFILE_NO_CLIENT && !(ra->flags & RESTART_VOLUME_IS_CLEAN)) { ntfs_debug("Done. $LogFile indicates a dirty shutdown."); return false; } /* $LogFile indicates a clean shutdown. */ ntfs_debug("Done. $LogFile indicates a clean shutdown."); return true; } /** * ntfs_empty_logfile - empty the contents of the $LogFile journal * @log_vi: struct inode of loaded journal $LogFile to empty * * Empty the contents of the $LogFile journal @log_vi and return 'true' on * success and 'false' on error. * * This function assumes that the $LogFile journal has already been consistency * checked by a call to ntfs_check_logfile() and that ntfs_is_logfile_clean() * has been used to ensure that the $LogFile is clean. */ bool ntfs_empty_logfile(struct inode *log_vi) { VCN vcn, end_vcn; ntfs_inode *log_ni = NTFS_I(log_vi); ntfs_volume *vol = log_ni->vol; struct super_block *sb = vol->sb; runlist_element *rl; unsigned long flags; unsigned block_size, block_size_bits; int err; bool should_wait = true; ntfs_debug("Entering."); if (NVolLogFileEmpty(vol)) { ntfs_debug("Done."); return true; } /* * We cannot use ntfs_attr_set() because we may be still in the middle * of a mount operation. Thus we do the emptying by hand by first * zapping the page cache pages for the $LogFile/$DATA attribute and * then emptying each of the buffers in each of the clusters specified * by the runlist by hand. */ block_size = sb->s_blocksize; block_size_bits = sb->s_blocksize_bits; vcn = 0; read_lock_irqsave(&log_ni->size_lock, flags); end_vcn = (log_ni->initialized_size + vol->cluster_size_mask) >> vol->cluster_size_bits; read_unlock_irqrestore(&log_ni->size_lock, flags); truncate_inode_pages(log_vi->i_mapping, 0); down_write(&log_ni->runlist.lock); rl = log_ni->runlist.rl; if (unlikely(!rl || vcn < rl->vcn || !rl->length)) { map_vcn: err = ntfs_map_runlist_nolock(log_ni, vcn, NULL); if (err) { ntfs_error(sb, "Failed to map runlist fragment (error " "%d).", -err); goto err; } rl = log_ni->runlist.rl; BUG_ON(!rl || vcn < rl->vcn || !rl->length); } /* Seek to the runlist element containing @vcn. */ while (rl->length && vcn >= rl[1].vcn) rl++; do { LCN lcn; sector_t block, end_block; s64 len; /* * If this run is not mapped map it now and start again as the * runlist will have been updated. */ lcn = rl->lcn; if (unlikely(lcn == LCN_RL_NOT_MAPPED)) { vcn = rl->vcn; goto map_vcn; } /* If this run is not valid abort with an error. */ if (unlikely(!rl->length || lcn < LCN_HOLE)) goto rl_err; /* Skip holes. */ if (lcn == LCN_HOLE) continue; block = lcn << vol->cluster_size_bits >> block_size_bits; len = rl->length; if (rl[1].vcn > end_vcn) len = end_vcn - rl->vcn; end_block = (lcn + len) << vol->cluster_size_bits >> block_size_bits; /* Iterate over the blocks in the run and empty them. */ do { struct buffer_head *bh; /* Obtain the buffer, possibly not uptodate. */ bh = sb_getblk(sb, block); BUG_ON(!bh); /* Setup buffer i/o submission. */ lock_buffer(bh); bh->b_end_io = end_buffer_write_sync; get_bh(bh); /* Set the entire contents of the buffer to 0xff. */ memset(bh->b_data, -1, block_size); if (!buffer_uptodate(bh)) set_buffer_uptodate(bh); if (buffer_dirty(bh)) clear_buffer_dirty(bh); /* * Submit the buffer and wait for i/o to complete but * only for the first buffer so we do not miss really * serious i/o errors. Once the first buffer has * completed ignore errors afterwards as we can assume * that if one buffer worked all of them will work. */ submit_bh(WRITE, bh); if (should_wait) { should_wait = false; wait_on_buffer(bh); if (unlikely(!buffer_uptodate(bh))) goto io_err; } brelse(bh); } while (++block < end_block); } while ((++rl)->vcn < end_vcn); up_write(&log_ni->runlist.lock); /* * Zap the pages again just in case any got instantiated whilst we were * emptying the blocks by hand. FIXME: We may not have completed * writing to all the buffer heads yet so this may happen too early. * We really should use a kernel thread to do the emptying * asynchronously and then we can also set the volume dirty and output * an error message if emptying should fail. */ truncate_inode_pages(log_vi->i_mapping, 0); /* Set the flag so we do not have to do it again on remount. */ NVolSetLogFileEmpty(vol); ntfs_debug("Done."); return true; io_err: ntfs_error(sb, "Failed to write buffer. Unmount and run chkdsk."); goto dirty_err; rl_err: ntfs_error(sb, "Runlist is corrupt. Unmount and run chkdsk."); dirty_err: NVolSetErrors(vol); err = -EIO; err: up_write(&log_ni->runlist.lock); ntfs_error(sb, "Failed to fill $LogFile with 0xff bytes (error %d).", -err); return false; } #endif /* NTFS_RW */