         cb         : undefined
 
     dbg = (m) -> winston.debug("rollback_to_snapshot(#{opts.project_id},#{opts.host},#{opts.snapshot}): #{m}")
-    snapshot = opts.snapshot
+    snapshot_name = opts.snapshot
     f = filesystem(opts.project_id)
 
     async.series([
         (cb) ->
-            if snapshot?
-                if snapshot.indexOf('@') == -1
-                    snapshot = opts.project_id + "@" + snapshot
+            if snapshot_name?
+                if snapshot_name.indexOf('@') == -1
+                    snapshot_name = opts.project_id + "@" + snapshot_name
                 cb()
             else
                 dbg("get most recent snapshot name")

                        if err
                            cb(err)
                        else
                            snapshot = output.stdout.trim()
                            cb()
        (cb) ->
            dbg("rollback to #{snapshot}")
            execute_on
                host    : opts.host
                command : "sudo zfs rollback #{snapshot}"
                timeout : 300
                cb      : cb
    ], (err) -> opts.cb?(err))

            else
                cb()
    ], opts.cb)

# Close every project on a given host -- useful for putting a node into maintenance
# mode or before a proper shutdown.  NOTE that the defaults here are different than
# for close_project, since this is aimed at maintenance and proper shutdown.
exports.close_all_projects = (opts) ->
    opts = defaults opts,
        host       : required
        unset_loc  : true          # set location to undefined in the database
        wait_for_replicate : true  # make sure that we successfully replicate each project everywhere, or returns an error.
        limit      : 10
        cb         : required
    dbg = (m) -> winston.debug("close_all_projects(host:#{opts.host},unset_loc:#{opts.unset_loc}): #{m}")
    errors = {}
    projects = undefined
    async.series([
        (cb) ->
            dbg("querying database...")
            database.select
                table   : 'projects'
                columns : ['project_id', 'location']
                json    : ['location']
                limit   : 1000000   # TODO: stupidly slow
                cb      : (err, result) ->
                    if result?
                        projects = (x[0] for x in result when x[1]?.host == opts.host)
                    dbg("got #{projects.length} projects")
                    cb(err)
        (cb) ->
            dbg("closing projects...")
            f = (project_id, cb) ->
                close_project
                    project_id : project_id
                    host       : opts.host
                    unset_loc  : opts.unset_loc
                    wait_for_replicate : opts.wait_for_replicate
                    cb         : (err) ->
                        if err
                            errors[project_id] = err
                        cb()
            async.mapLimit(projects, opts.limit, f, cb)
    ], (err) ->
        if err
            errors['err'] = err
        if misc.len(errors) == 0
            opts.cb()
        else
            opts.cb(errors)
    )


# Call "close_project"  on all projects that have been open for
# more than ttl seconds, where opened means that location is set.
